package com.xiaochun.hxhj;


import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.method.ScrollingMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.widget.TextViewCompat;

import com.adapter.NineTableAdapter;
import com.adapter.NineTableNumAdapter;
import com.bean.AnswerQuesBean;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.RecognizerListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechRecognizer;
import com.iflytek.cloud.ui.RecognizerDialog;
import com.myview.CustomProgressDialog;
import com.myview.MyGraidView;
import com.myview.PaletteView;
import com.util.DensityUtil;
import com.util.DownUtil;
import com.util.GlideUtils;
import com.util.JsonParser;
import com.util.MyLog;
import com.util.RequestManager;
import com.util.ToastUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
//记忆力测试  MemoryTestActivity   备份删方法

public class MemoryTestActivity2 extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.ll_rebacka)
    LinearLayout ll_rebacka;
    @BindView(R.id.ll_reback_two)
    LinearLayout ll_reback_two;
    @BindView(R.id.ll_splash)
    LinearLayout ll_splash;
    @BindView(R.id.gridview_ninetable)
    MyGraidView gridview_ninetable;
    @BindView(R.id.ll_nine_table)
    RelativeLayout ll_nine_table;
    @BindView(R.id.ll_subject_content)
    LinearLayout ll_subject_content;
    @BindView(R.id.ll_listener_rember)
    RelativeLayout ll_listener_rember;
    @BindView(R.id.tv_splash_tv)
    TextView tv_splash_tv;
    @BindView(R.id.tv_listener_rember)
    TextView tv_listener_rember;
    @BindView(R.id.tv_listener_remark)
    TextView tv_listener_remark;
    @BindView(R.id.img_record)
    ImageView img_record;//词语语段录音
    @BindView(R.id.ll_listener_next_subject)
    ImageView ll_listener_next_subject;//词语语段下一题
    @BindView(R.id.tv_nine_title)
    TextView tv_nine_title;
    @BindView(R.id.tv_ninetable_desc)
    TextView tv_ninetable_desc;
    @BindView(R.id.tv_remark)
    TextView tv_remark;
    @BindView(R.id.ll_rember_num)
    RelativeLayout ll_rember_num;
    @BindView(R.id.tv_rember_num_content)
    TextView tv_rember_num_content;
    @BindView(R.id.ll_see_img)
    LinearLayout ll_see_img;
    @BindView(R.id.img_see_img_content)
    ImageView img_see_img_content;
    @BindView(R.id.tv_see_img_question_title)
    TextView tv_see_img_question_title;
    @BindView(R.id.ll_selectA)
    LinearLayout ll_selectA;
    @BindView(R.id.tv_select_answerA)
    TextView tv_select_answerA;
    @BindView(R.id.img_answerA)
    ImageView img_answerA;
    @BindView(R.id.ll_selectB)
    LinearLayout ll_selectB;
    @BindView(R.id.tv_select_answerB)
    TextView tv_select_answerB;
    @BindView(R.id.img_answerB)
    ImageView img_answerB;
    @BindView(R.id.ll_selectC)
    LinearLayout ll_selectC;
    @BindView(R.id.tv_select_answerC)
    TextView tv_select_answerC;
    @BindView(R.id.img_answerC)
    ImageView img_answerC;
    @BindView(R.id.ll_see_img_question)
    LinearLayout ll_see_img_question;
    @BindView(R.id.tv_listener_rember_title)
    TextView tv_listener_rember_title;
    @BindView(R.id.ll_end)
    LinearLayout ll_end;
    @BindView(R.id.tv_jyname)
    TextView tv_jyname;
    @BindView(R.id.tv_jycontent)
    TextView tv_jycontent;
    @BindView(R.id.ll_reback_end)
    LinearLayout ll_reback_end;
    @BindView(R.id.rl_start)
    RelativeLayout rl_start;
    @BindView(R.id.ll_reback_start)
    LinearLayout ll_reback_start;
    @BindView(R.id.tv_kc_name)
    TextView tv_kc_name;
    @BindView(R.id.tv_kc_content)
    TextView tv_kc_content;
    @BindView(R.id.pb_main_downloadone)
    ProgressBar pb_main_downloadone;
    @BindView(R.id.ll_more_subject)
    LinearLayout ll_more_subject;
    @BindView(R.id.ll_more_splash)
    LinearLayout ll_more_splash;
    @BindView(R.id.ll_more_sart)
    LinearLayout ll_more_sart;
    @BindView(R.id.ll_more_end)
    LinearLayout ll_more_end;
    @BindView(R.id.img_listener_floor)
    ImageView img_listener_floor;
    @BindView(R.id.ll_start_jump)
    LinearLayout ll_start_jump;//课程开始页面跳过
    @BindView(R.id.tv_splash_known)
    TextView tv_splash_known;//引导页面知道了
    @BindView(R.id.ll_select_item)
    LinearLayout ll_select_item;//图片题型的选择项布局
    @BindView(R.id.img_listener_bowen)
    ImageView img_listener_bowen;//词语语段录音波纹
    @BindView(R.id.ll_draw_pic)
    LinearLayout ll_draw_pic;//画图父布局
    @BindView(R.id.rl_draw_subject)
    RelativeLayout rl_draw_subject;//画图呈现原图
    @BindView(R.id.tv_draw_title)
    TextView tv_draw_title;//图片标题
    @BindView(R.id.img_stand_pic)
    ImageView img_stand_pic;//图片加载
    @BindView(R.id.rl_draw)
    RelativeLayout rl_draw;//画布呈现
    @BindView(R.id.ll_chexiao)
    LinearLayout ll_chexiao;//画画撤销
    @BindView(R.id.ll_retry_draw)
    LinearLayout ll_retry_draw;//重画
    @BindView(R.id.img_draw)
    PaletteView img_draw;//画布
    @BindView(R.id.tv_seeimg_try)
    TextView tv_seeimg_try;//再看一次
    @BindView(R.id.tv_redraw)
    TextView tv_redraw;//再画一次
    @BindView(R.id.tv_draw_ok)
    TextView tv_draw_ok;//我画好了
    @BindView(R.id.tv_draw_now)
    TextView tv_draw_now;//直接画画
    @BindView(R.id.ll_draw_btn)
    LinearLayout ll_draw_btn;//画画按钮父布局
    @BindView(R.id.ll_contrast)
    LinearLayout ll_contrast;//画画比较父布局
    @BindView(R.id.img_show_stand_pic)
    ImageView img_show_stand_pic;//画画比较原图
    @BindView(R.id.img_show_draw_pic)
    ImageView img_show_draw_pic;//画画比较作者图
    @BindView(R.id.rl_shan_num)
    RelativeLayout rl_shan_num;//数字闪记父布局
    @BindView(R.id.tv_shannum_num)
    TextView tv_shannum_num;//闪记数字
    @BindView(R.id.ll_shan_content)
    LinearLayout ll_shan_content;//闪记数字答案父布局
    @BindView(R.id.tv_shan_question)
    TextView tv_shan_question;//闪记正确答案
    @BindView(R.id.tv_shan_answer)
    TextView tv_shan_answer;//闪记用户答案
    @BindView(R.id.rl_long_num)
    LinearLayout rl_long_num;//长串数字记忆父布局
    @BindView(R.id.tv_longnum_num)
    TextView tv_longnum_num;//长串数字
    @BindView(R.id.ll_longnum_question)
    LinearLayout ll_longnum_question;//长串数字问题
    @BindView(R.id.tv_longnum_question_title)
    TextView tv_longnum_question_title;//长串数字问题标题
    @BindView(R.id.et_longnum_input)
    EditText et_longnum_input;//长串数字问题输入框
    @BindView(R.id.tv_longnum_sure)
    TextView tv_longnum_sure;//长串数字提交答案
    @BindView(R.id.ll_end_daka)
    LinearLayout ll_end_daka;//完成学习打卡页面
    @BindView(R.id.ll_reback_enddaka)
    LinearLayout ll_reback_enddaka;//完成学习打卡返回键
    @BindView(R.id.ll_more_enddaka)
    LinearLayout ll_more_enddaka;//完成学习打卡更多
    @BindView(R.id.tv_study_over)
    TextView tv_study_over;//完成学习打卡
    @BindView(R.id.ll_end_share)
    LinearLayout ll_end_share;//分享页面父布局
    @BindView(R.id.ll_reback_endshare)
    LinearLayout ll_reback_endshare;//分享页面返回
    @BindView(R.id.ll_more_endshare)
    LinearLayout ll_more_endshare;//分享页面更多
    @BindView(R.id.img_userlogo)
    ImageView img_userlogo;//用户头像
    @BindView(R.id.tv_username)
    TextView tv_username;//用户名字
    @BindView(R.id.tv_score)
    TextView tv_score;//分数
    @BindView(R.id.tv_study_day)
    TextView tv_study_day;//学习天数
    @BindView(R.id.tv_daka_day)
    TextView tv_daka_day;//打卡天数
    @BindView(R.id.tv_share_wxp)
    TextView tv_share_wxp;//分享微信朋友圈
    @BindView(R.id.ll_long_num_ques_fu)
    LinearLayout ll_long_num_ques_fu;//记数字游戏的问题父布局
    @BindView(R.id.tv_long_num_que)
    TextView tv_long_num_que;//记数字游戏数字上方的问题
    @BindView(R.id.tv_start_answer)
    TextView tv_start_answer;//记数字游戏数字开始答题
    @BindView(R.id.ll_subject_content2)
    RelativeLayout ll_subject_content2;//题目内容2
    @BindView(R.id.ll_ciyu_jiaocheng)
    LinearLayout ll_ciyu_jiaocheng;//词语教程
    @BindView(R.id.tv_ciyu_title)
    TextView tv_ciyu_title;//词语教程  标题
    @BindView(R.id.tv_ciyu_content)
    TextView tv_ciyu_content;//词语教程 内容
    @BindView(R.id.tv_ciyu_known)
    TextView tv_ciyu_known;//词语教程 知道了
    @BindView(R.id.ll_num_answer)
    LinearLayout ll_num_answer;//数字记忆答题父布局
    @BindView(R.id.et_num_input)
    EditText et_num_input;//数字记忆答题输入框
    @BindView(R.id.tv_num_sure)
    TextView tv_num_sure;//数字记忆答题确认按钮
    @BindView(R.id.ll_ci_answer)
    LinearLayout ll_ci_answer;//词语句子答题布局
    @BindView(R.id.et_ci_input)
    EditText et_ci_input;//词语句子答题输入框
    @BindView(R.id.tv_ci_sure)
    TextView tv_ci_sure;//词语句子答案确定
    @BindView(R.id.ll_end_memory)
    LinearLayout ll_end_memory;//记忆力测试结束页面
    @BindView(R.id.ll_end_end)
    LinearLayout ll_end_end;//记忆力测试结束返回按钮
    @BindView(R.id.ll_more_endend)
    LinearLayout ll_more_endend;//记忆力测试结束更多按钮
    @BindView(R.id.ll_scros)
    LinearLayout ll_scros;//记忆力测试分数父布局
    @BindView(R.id.tv_check_course)
    TextView tv_check_course;//快来挑选适合你的记忆力课吧
    @BindView(R.id.tv_score_ciyu)
    TextView tv_score_ciyu;//词语分数
    @BindView(R.id.tv_score_num)
    TextView tv_score_num;//数字分数
    @BindView(R.id.tv_score_kanji)
    TextView tv_score_kanji;//看记分数
    @BindView(R.id.tv_score_tingji)
    TextView tv_score_tingji;//听记分数
    @BindView(R.id.tv_score_danci)
    TextView tv_score_danci;//单词分数
    @BindView(R.id.tv_score_total)
    TextView tv_score_total;//总计分数


    private boolean isExit = false;
    private boolean isNineTableClick = false;
    private CustomProgressDialog customProgressDialog;
    private List<AnswerQuesBean.DataBean> answerqueList = new ArrayList<>();
    private NineTableAdapter nineTableAdapter;
    public int subjectitem = 0;//当前是第几题
    public String clickitemstr = "";//正确的条目数，根据另外一个参数（true   false）来判断最后一个条目是正确的还是错误的
    public String clickitemstrTemp = "";//临时正确的条目数，根据另外一个参数（true   false）来判断最后一个条目是正确的还是错误的
    public int rightcount = 0;//九宫格可点击图片的正确数目
    private NineTableNumAdapter nineTableNunAdapter;
    public int sequenceflag = 0;
    private String opt_result;
    private String opt_result1;
    private static MediaPlayer mediaPlayer;
    private RecognizerDialog mIatDialog;//语音听写ui
    // 语音听写对象
    private SpeechRecognizer mIat;
    // 引擎类型
    private String mEngineType = SpeechConstant.TYPE_CLOUD;
    private String resultType = "json";
    // 用HashMap存储听写结果
    private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
    public String voiceContent = "";
    private String jyname;
    private String jycontent;
    public boolean isintosplash = false;
    private String course_content;
    private String course_title;
    private int screenwidth;
    private int screenheightPixels;
    private int itemwidth;
    private PopupWindow mPopupResultWindow;
    int ret = 0; // 函数调用返回值
    private StringBuffer buffer = new StringBuffer();
    private int subjectType = -1;//细分课程题目类型
    private boolean isvoice = false;//录音按钮是否可点击
    private boolean iscanvoice = false;//是否可录音
    private String splashtypes = "";//题型引导页类型（当前类型）用于判断当前题和上一个题是不是属于同一个类型，是否显示引导页
    private String splashtypeslast = "";//题型引导页类型(上一个类型)用于判断当前题和上一个题是不是属于同一个类型，是否显示引导页
    public String numberstr = "";//看记和听记数字  字符串
    public String numberstrback = "";//看记和听记数字  字符串   倒背正确答案
    public String voicenumberstr = "";//学生录音正背结果
    public String voicenumberstrback = "";//学生录音倒背结果
    private boolean isp;
    private Handler handlerdelay;
    private String token;
    private List<String> medialists = new ArrayList<>();
    private List<String> unitlists = new ArrayList<>();
    private List<String> drawids = new ArrayList<>();
    private List<String> clicknineitems = new ArrayList<>();
    private boolean isaddflag = true;
    private String studyscore;
    private String dakaday;
    private String studyday;
    private String catelog_id;
    private String course_id;
    private PopupWindow mPopupWindowexit;
    private List<String> videourllist = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        customProgressDialog = new CustomProgressDialog(context, "", R.style.CommProgressDialog);
        WindowManager.LayoutParams params = customProgressDialog.getWindow().getAttributes();
        params.alpha = 0.7f;//取值为0-1之间  0是全透明，1是不透明
        params.dimAmount = 0f;   //取值为0-1之间  1是全黑
        customProgressDialog.getWindow().setAttributes(params);
        customProgressDialog.show();
        handlerdelay = new Handler();

    }

    @Override
    protected void initListener() {
        tv_splash_known.setOnClickListener(this);
        ll_start_jump.setOnClickListener(this);
        ll_more_end.setOnClickListener(this);
        ll_more_sart.setOnClickListener(this);
        ll_more_splash.setOnClickListener(this);
        ll_more_subject.setOnClickListener(this);
        img_record.setOnClickListener(this);
        ll_selectA.setOnClickListener(this);
        ll_selectB.setOnClickListener(this);
        ll_selectC.setOnClickListener(this);
        ll_listener_next_subject.setOnClickListener(this);
        ll_rebacka.setOnClickListener(this);
        ll_reback_two.setOnClickListener(this);
        ll_reback_start.setOnClickListener(this);
        ll_reback_end.setOnClickListener(this);
        ll_chexiao.setOnClickListener(this);
        ll_retry_draw.setOnClickListener(this);
        tv_longnum_sure.setOnClickListener(this);
        tv_study_over.setOnClickListener(this);
        tv_start_answer.setOnClickListener(this);
        tv_check_course.setOnClickListener(this);
        tv_num_sure.setOnClickListener(this);
        tv_ci_sure.setOnClickListener(this);
        ll_end_end.setOnClickListener(this);


        gridview_ninetable.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if ("3".equals(answerqueList.get(subjectitem).getTypes())) {
                    //九宫格数字
                    if (isNineTableClick) {
                        boolean isadd = true;
                        for (int c = 0; c < clicknineitems.size(); c++) {
                            String s = clicknineitems.get(c);
                            if (s.equals(i + "")) {
                                isadd = false;
                                break;
                            }
                        }
                        if (isadd) {
                            clicknineitems.add(i + "");
                            sequenceflag++;//点击次数
                            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                            int size = answer.size();
                            if ("".equals(clickitemstrTemp)) {
                                for (int m = 0; m < size; m++) {
                                    String opt1 = answer.get(m).getOpt_answer();
                                    if (!"0".equals(opt1)) {
                                        rightcount++;
                                        if ("".equals(clickitemstrTemp)) {
                                            clickitemstrTemp = m + "-";
                                        } else {
                                            clickitemstrTemp = clickitemstrTemp + m + "-";
                                        }
                                    }
                                }
                            }


                            String opt = answer.get(i).getOpt_answer();
                            if (opt.equals(sequenceflag + "")) {
                                //当前点击无误，刷新九宫格
                                boolean isp = true;
                                String[] split = clickitemstr.split("-");
                                for (int k = 0; k < split.length; k++) {
                                    String s = split[k];
                                    if (s.equals("" + i)) {
                                        isp = false;
                                        break;
                                    }
                                }
                                if (isp) {
                                    if ("".equals(clickitemstr)) {
                                        clickitemstr = i + "-";
                                    } else {
                                        clickitemstr = clickitemstr + i + "-";
                                    }
                                    nineTableNunAdapter.setCheckedItem(i, clickitemstr, true);
                                    if (sequenceflag == rightcount) {
                                        isNineTableClick = false;
                                        clickitemstrTemp = "";
                                        clickitemstr = "";
                                        sequenceflag = 0;
                                        rightcount = 0;
                                        setMusicUrl("6", "","14");//initMusicplay("a03", "", "");原initMusicplay("a03", "6", "");
                                        tv_remark.setText("全部正确，你的回答真棒！");
                                        tv_remark.setVisibility(View.VISIBLE);
                                    }
                                }
                            } else {
                                //当前点击有误，正确答案全部显示，播报语音
                                nineTableNunAdapter.setCheckedItem(i, clickitemstr, false);
                                isNineTableClick = false;
                                clickitemstrTemp = "";
                                clickitemstr = "";
                                sequenceflag = 0;
                                rightcount = 0;
                                setMusicUrl("6", "","30");//initMusicplay("a04", "6", "");原initMusicplay("a04", "6", "");
                                tv_remark.setText("没关系的，继续努力!");
                                tv_remark.setVisibility(View.VISIBLE);
                            }
                        } else {

                        }

                    }
                } else {
                    //九宫格其他类型
                    if (isNineTableClick) {
                        List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                        int type = answerqueList.get(subjectitem).getType() - 1;
                        int size = answer.size();

                        if ("".equals(clickitemstrTemp)) {
                            for (int m = 0; m < size; m++) {
                                String opt1 = answer.get(m).getOpt_answer();
                                if ("1".equals(opt1)) {
                                    rightcount++;
                                    if ("".equals(clickitemstrTemp)) {
                                        clickitemstrTemp = m + "-";
                                    } else {
                                        clickitemstrTemp = clickitemstrTemp + m + "-";
                                    }
                                }
                            }
                        }
                        String opt = answer.get(i).getOpt_answer();
                        if ("0".equals(opt)) {
                            //错误
                            clickitemstr = "";//如果之前点击的有正确的，那么需要清空条目标签
                            clickitemstr = clickitemstrTemp + i;
                            nineTableAdapter.setCheckedItem(i, clickitemstr, false);
                            clickitemstrTemp = "";
                            isNineTableClick = false;
                            rightcount = 0;
                            setMusicUrl(type+"", "","30");//        initMusicplay("a04", type + "", "");原initMusicplay("a04", type + "", "");
                            tv_remark.setText("没关系的，继续努力!");
                            tv_remark.setVisibility(View.VISIBLE);
                            clickitemstr = "";

                        } else {
                            //正确
                            boolean isp = true;
                            String[] split = clickitemstr.split("-");
                            for (int k = 0; k < split.length; k++) {
                                String s = split[k];
                                if (s.equals("" + i)) {
                                    isp = false;
                                    break;
                                }
                            }

                            if (isp) {
//                            if (!clickitemstr.contains(i + "")) {
                                if ("".equals(clickitemstr)) {
                                    clickitemstr = i + "-";
                                } else {
                                    clickitemstr = clickitemstr + i + "-";
                                }
                                int rightanswer = clickitemstr.split("-").length;
                                nineTableAdapter.setCheckedItem(i, clickitemstr, true);
                                if (rightanswer == rightcount) {
                                    isNineTableClick = false;
                                    clickitemstrTemp = "";
                                    clickitemstr = "";
                                    rightcount = 0;
                                    setMusicUrl(type+"", "","14");//        initMusicplay("a03", type + "", "");原initMusicplay("a03", type + "", "");
                                    tv_remark.setText("全部正确，你的回答真棒！");
                                    tv_remark.setVisibility(View.VISIBLE);
                                }
                            }


                        }


                    }
                }

            }
        });
        img_record.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        //听记录音
                        MyLog.e("是否可以录音", iscanvoice + "   438行");
                        if (iscanvoice) {
                            closeMediaplayer();
                            tv_listener_rember.setText("");
                            img_listener_bowen.setVisibility(View.VISIBLE);
                            Glide.with(context)
                                    .load(R.mipmap.icon_bowen)
                                    .into(img_listener_bowen);
                            closeMediaplayer();
                            // 设置参数
                            setParam();
                /*// 显示听写对话框
                mIatDialog.setListener(mRecognizerDialogListener);
                mIatDialog.show();*/
                            // 不显示听写对话框
                            ret = mIat.startListening(mRecognizerListener);
                            if (ret != ErrorCode.SUCCESS) {
                                ToastUtils.show("听写失败,错误码：" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
                            } else {
                                ToastUtils.show("请开始说话");
                            }
                        }
                        break;
                    case MotionEvent.ACTION_MOVE:
                        break;
                    case MotionEvent.ACTION_UP:
                        MyLog.e("是否可以录音", iscanvoice + "   459行");
                        if (iscanvoice) {
                            mIat.stopListening();
                            //听记
                            img_listener_floor.setVisibility(View.INVISIBLE);
//                            iscanvoice = false;
                            MyLog.e("是否可以录音", iscanvoice + "   65行");
                            img_listener_bowen.setVisibility(View.GONE);
                            String str = "";
                            for (int i = 0; i < unitlists.size(); i++) {
                                String s = unitlists.get(i);
                                str = str + "  " + s;
                            }
                            if (!"".equals(voiceContent)) {
                                tv_listener_rember.setText("标准答案：" + str);
                            }
                        }
                        break;
                }
                return false;
            }
        });
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_memorytest;
    }

    @Override
    protected void initView() {
//        xiangsimain();
        getScreenDen();
        changeTitle("首页");
        showRightView(false);
        hideTitleBar();
//        saveUserInfo("bookid","1");
        token = getUserInfo("token");
        course_id = getIntent().getStringExtra("course_id");
        catelog_id = getIntent().getStringExtra("catelog_id");

        course_title = getIntent().getStringExtra("course_title");
        course_content = getIntent().getStringExtra("course_content");
        tv_kc_name.setText(course_title);
        tv_kc_content.setText(course_content);
        //根据路径得到Typeface
//        Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/kai.ttf");//仿宋
//        tv_nine_title.setTypeface(tf);

        setMusicUrl("", "","1");//        initMusicplay("a01", "", "");initMusicplay("a01", "", "");
        getData();
        getJyData();
        // 初始化识别无UI识别对象
        // 使用SpeechRecognizer对象，可根据回调消息自定义界面；
        mIat = SpeechRecognizer.createRecognizer(context, mInitListener);

        // 初始化听写Dialog，如果只使用有UI听写功能，无需创建SpeechRecognizer
        // 使用UI听写功能，请根据sdk文件目录下的notice.txt,放置布局文件和图片资源
        mIatDialog = new RecognizerDialog(context, mInitListener);
        if (Build.VERSION.SDK_INT >= 26) {
//            tv_longnum_num.setAutoSizeTextTypeUniformWithConfiguration(8, 100,2, TypedValue.COMPLEX_UNIT_SP);
            TextViewCompat.setAutoSizeTextTypeWithDefaults(tv_longnum_num, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
            tv_longnum_num.setAutoSizeTextTypeUniformWithConfiguration(10, 44,2, TypedValue.COMPLEX_UNIT_DIP);
        }else{
            TextViewCompat.setAutoSizeTextTypeWithDefaults(tv_longnum_num, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);

        }
        tv_listener_rember.setMovementMethod(ScrollingMovementMethod.getInstance());

    }

    @Override
    protected void initData() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_rebacka:
            case R.id.ll_reback_two:
            case R.id.ll_reback_start:
                //记忆力测试挑选适合自己的课程
                myapp.scoretingji = 0;
                myapp.scorekanji = 0;
                myapp.scorenum = 0;
                myapp.scoreciyu = 0;
                myapp.scoredanci = 0;
                popbyexit();
                break;
            case R.id.ll_reback_end:
            case R.id.ll_end_end:
            case R.id.tv_check_course:
                //记忆力测试挑选适合自己的课程
                finish();
                break;

            case R.id.ll_nextquestion_nineimg:
                //九宫格类型下一题
                iscanvoice = false;
                currentposi = -1;
                codeLen = 0;
                handlerdelay.removeCallbacksAndMessages(null);
                closeMediaplayer();
                subjectitem++;
                setQuestion(subjectitem);
                break;
            case R.id.ll_lastquestion_nineimg:
                //九宫格类型上一题
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    iscanvoice = false;
                    currentposi = -1;
                    handlerdelay.removeCallbacksAndMessages(null);
                    codeLen = 0;
                    closeMediaplayer();
                    subjectitem--;
                    setQuestion(subjectitem);
                }
                break;
            case R.id.ll_listener_next_subject:
                //听记类型下一题
                currentposi = -1;
                handlerdelay.removeCallbacksAndMessages(null);
                codeLen = 0;
                closeMediaplayer();
                isvoice = false;
                iscanvoice = false;
                tv_rember_num_content.setText("");
                voiceContent = "";
                subjectitem++;
                setQuestion(subjectitem);
                break;
            case R.id.ll_rember_last_subject:
                //词语语段上一题
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    currentposi = -1;
                    handlerdelay.removeCallbacksAndMessages(null);
                    codeLen = 0;
                    closeMediaplayer();
                    isvoice = false;
                    iscanvoice = false;
                    tv_rember_num_content.setText("");
                    voiceContent = "";
                    subjectitem--;
                    setQuestion(subjectitem);
                }
                break;

            case R.id.ll_rember_num_next_subject:
                //倒背正背数字类型下一题
                currentposi = -1;
                handlerdelay.removeCallbacksAndMessages(null);
                if (timer != null && mTask != null) {
                    mTask.cancel();
                }
                iscanvoice = false;
                codeLen = 0;
                closeMediaplayer();
                isvoice = false;
                tv_rember_num_content.setText("");
                voiceContent = "";
                numberstr = "";
                numberstrback = "";
                voicenumberstr = "";
                voicenumberstrback = "";
                subjectitem++;
                setQuestion(subjectitem);
                break;
            case R.id.ll_rember_num_last_subject:
                //倒背正背数字类型上一题
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    iscanvoice = false;
                    currentposi = -1;
                    handlerdelay.removeCallbacksAndMessages(null);
                    codeLen = 0;
                    closeMediaplayer();
                    isvoice = false;
                    tv_rember_num_content.setText("");
                    voiceContent = "";
                    numberstr = "";
                    numberstrback = "";
                    voicenumberstr = "";
                    voicenumberstrback = "";
                    subjectitem--;
                    setQuestion(subjectitem);
                }
                break;

            case R.id.img_record:

                break;
            case R.id.img_rember_num_record:

                break;
            case R.id.img_shannum_record:

                break;
            case R.id.ll_more_end:
                popbygrade(ll_more_end);
                break;
            case R.id.ll_more_sart:
                popbygrade(ll_more_sart);
                break;
            case R.id.ll_more_splash:
                popbygrade(ll_more_splash);
                break;
            case R.id.ll_more_subject:
                popbygrade(ll_more_subject);
                break;
            case R.id.ll_start_jump:
                //课程开始页面跳过事件，音频停止播放，开始第一个题型的引导页
                codeLen = 0;
                closeMediaplayer();
                rl_start.setVisibility(View.GONE);
                ll_splash.setVisibility(View.VISIBLE);
                if (!isintosplash) {
                    if (answerqueList.size() > 0) {
                        isintosplash = true;
                        subjectitem = 0;
                        setQuestion(0);
                    }
                }
                break;
            case R.id.tv_splash_known:
                if ("1".equals(splashtypes)) {
                    //图片选择题
                    closeMediaplayer();
                    setViewData("a08", subjectType + "");
                } else if ("2".equals(splashtypes)) {
                    //九宫格图案
                    closeMediaplayer();
                    setViewData("a26", subjectType + "");
                } else if ("3".equals(splashtypes)) {
                    //3=九宫格数字
                    closeMediaplayer();
                    setViewData("a06", subjectType + "");
                } else if ("4".equals(splashtypes)) {
                    //4=看记数字-正背倒背
                    closeMediaplayer();
                    setViewData("a10", subjectType + "");
                } else if ("5".equals(splashtypes)) {
                    //5=听记数字-正背倒背
                    closeMediaplayer();
                    setViewData("a29", subjectType + "");
                } else if ("6".equals(splashtypes)) {
                    //6=词语跟读
                    closeMediaplayer();
                    setViewData("a15", subjectType + "");
                } else if ("7".equals(splashtypes)) {
                    //7听力-选择题
                } else if ("9".equals(splashtypes)) {
                    //9数字滚动
                    closeMediaplayer();
                    setViewData("a32", subjectType + "");
                } else if ("10".equals(splashtypes)) {
                    //10看记数字
                    closeMediaplayer();
                    setViewData("a10", subjectType + "");
                } else if ("11".equals(splashtypes)) {
                    //11长串数字记忆
                    closeMediaplayer();
                    setViewData("a33", subjectType + "");
                }
                break;
            case R.id.ll_nextquestion:
                //图片题型的下一题
                iscanvoice = false;
                currentposi = -1;
                handlerdelay.removeCallbacksAndMessages(null);
                codeLen = 0;
                closeMediaplayer();
                int listsize = answerqueList.size();
                if (subjectitem == listsize - 1) {
                    ToastUtils.show("当前已是最后一题");
                } else {
                    handlerdelay.removeCallbacksAndMessages(null);
                    codeLen = codeLentemp;
                    subjectitem++;
                    setQuestion(subjectitem);
                }
                break;
            case R.id.ll_lastquestion:
                //图片题型的上一题
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    iscanvoice = false;
                    currentposi = -1;
                    handlerdelay.removeCallbacksAndMessages(null);
                    codeLen = 0;
                    closeMediaplayer();
                    if (subjectitem == 0) {
                        ToastUtils.show("当前已是第一题");
                    } else {
                        handlerdelay.removeCallbacksAndMessages(null);
                        codeLen = codeLentemp;
                        subjectitem--;
                        setQuestion(subjectitem);
                    }
                }
                break;
            case R.id.ll_chexiao:
                //撤销
                img_draw.undo();
                break;
            case R.id.ll_retry_draw:
                //重置
                img_draw.clear();
                break;
            case R.id.tv_redraw:
                //再画一次
                closeMediaplayer();
                handlerdelay.removeCallbacksAndMessages(null);
                codeLen = 0;
                img_draw.clear();
                rl_draw_subject.setVisibility(View.VISIBLE);
                rl_draw.setVisibility(View.GONE);
                ll_contrast.setVisibility(View.GONE);
                ll_retry_draw.setVisibility(View.VISIBLE);
                tv_draw_now.setVisibility(View.VISIBLE);
                tv_seeimg_try.setVisibility(View.GONE);
                tv_draw_ok.setVisibility(View.GONE);
                tv_redraw.setVisibility(View.GONE);
                setQuestion(subjectitem);
                break;
            case R.id.tv_seeimg_try:
                //再看一次
                handlerdelay.removeCallbacksAndMessages(null);
                codeLen = 0;
                img_draw.clear();
                rl_draw_subject.setVisibility(View.VISIBLE);
                rl_draw.setVisibility(View.GONE);
                ll_contrast.setVisibility(View.GONE);
                ll_retry_draw.setVisibility(View.VISIBLE);
                tv_draw_now.setVisibility(View.VISIBLE);
                tv_seeimg_try.setVisibility(View.GONE);
                tv_draw_ok.setVisibility(View.GONE);
                setQuestion(subjectitem);
                break;
            case R.id.tv_draw_ok:
                //我画好了
                ll_contrast.setVisibility(View.VISIBLE);
                rl_draw_subject.setVisibility(View.GONE);
                rl_draw.setVisibility(View.GONE);
                tv_draw_ok.setVisibility(View.GONE);
                tv_seeimg_try.setVisibility(View.GONE);
                img_draw.saveImg(img_draw.buildBitmap());
                ll_draw_btn.setVisibility(View.VISIBLE);
                tv_redraw.setVisibility(View.VISIBLE);
                String image = answerqueList.get(subjectitem).getImage();
                GlideUtils.loadImage(context, image, img_show_stand_pic);
//                img_show_draw_pic
                Bitmap imagePath = getImagePath();
                img_show_draw_pic.setImageBitmap(imagePath);
                setMusicUrl(subjectType+"", "","31");//        initMusicplay("a36", subjectType + "", "");initMusicplay("a12", subjectType + "", "");
                break;
            case R.id.tv_draw_now:
                //直接画画
                rl_draw_subject.setVisibility(View.GONE);
                rl_draw.setVisibility(View.VISIBLE);
                ll_contrast.setVisibility(View.GONE);
                handlerdelay.removeCallbacksAndMessages(null);
                codeLen = 0;
                img_draw.clear();
                tv_nine_title.setText("请画出刚才所看到的图形");
                ll_retry_draw.setVisibility(View.VISIBLE);
                tv_draw_now.setVisibility(View.GONE);
                tv_seeimg_try.setVisibility(View.VISIBLE);
                tv_draw_ok.setVisibility(View.VISIBLE);
                break;
            case R.id.img_draw_last_subject:
                //画画上一题
                closeMediaplayer();
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    handlerdelay.removeCallbacksAndMessages(null);
                    codeLen = 0;
                    img_draw.clear();
                    rl_draw_subject.setVisibility(View.VISIBLE);
                    rl_draw.setVisibility(View.GONE);
                    ll_contrast.setVisibility(View.GONE);
                    tv_redraw.setVisibility(View.GONE);
                    subjectitem--;
                    setQuestion(subjectitem);
                }
                break;
            case R.id.img_draw_next_subject:
                //画画下一题
                closeMediaplayer();
                handlerdelay.removeCallbacksAndMessages(null);
                codeLen = 0;
                img_draw.clear();
                rl_draw_subject.setVisibility(View.VISIBLE);
                rl_draw.setVisibility(View.GONE);
                ll_contrast.setVisibility(View.GONE);
                tv_redraw.setVisibility(View.GONE);
                subjectitem++;
                setQuestion(subjectitem);
                break;
            case R.id.img_shannum_last_subject:
                //闪记上一题
                closeMediaplayer();
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    iscanvoice = false;
                    subjectitem--;
                    setQuestion(subjectitem);
                }
                break;
            case R.id.img_shannum_next_subject:
                //闪记下一题
                closeMediaplayer();
                iscanvoice = false;
                subjectitem++;
                setQuestion(subjectitem);
                break;

            case R.id.tv_longnum_sure:
                //长串数字提交答案
                String trim = et_longnum_input.getText().toString().trim();
                if ("".equals(trim)) {
                    ToastUtils.show("请先输入你的答案");
                } else {
                    if (DensityUtil.isFastDoubleClick()) {
                        return;
                    }

                    longqueitem++;
                    String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
                    List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                    int size = answer.size();
                    String str = "";
                    if (size > 0) {
                        if (longqueitem < size){
                            str = answer.get(longqueitem).getOpt_answer();
                            int queitem = longqueitem+1;
                            tv_long_num_que.setText("问题"+queitem+":"+str);
                            tv_longnum_num.setText(course_list_name);
                            tv_longnum_num.setMovementMethod(ScrollingMovementMethod.getInstance());
                            tv_nine_title.setText("根据问题观察下面数字");
                            ll_longnum_question.setVisibility(View.GONE);
                            ll_long_num_ques_fu.setVisibility(View.VISIBLE);
                            tv_start_answer.setVisibility(View.VISIBLE);
                        }else{
                            ToastUtils.show("已全部做完");
                        }
                    }

                }
                break;
            case R.id.img_longnum_last_subject:
                //长串数字上一题
                closeMediaplayer();
                if (subjectitem == 0) {
                    ToastUtils.show("当前已是第一题");
                } else {
                    et_longnum_input.setText("");
                    iscanvoice = false;
                    subjectitem--;
                    setQuestion(subjectitem);
                }
                break;
            case R.id.img_longnum_next_subject:
                //长串数字下一题
                et_longnum_input.setText("");
                closeMediaplayer();
                iscanvoice = false;
                subjectitem++;
                setQuestion(subjectitem);
                break;
            case R.id.tv_study_over:
                //完成学习打卡
                getShareData();
                ll_end_daka.setVisibility(View.GONE);
                ll_end_share.setVisibility(View.VISIBLE);
                String nickname = getUserInfo("nickname");
                String avatar = getUserInfo("avatar");
                tv_username.setText("Hi，" + nickname);
                GlideUtils.loadCircleImage(context, avatar, img_userlogo);
                break;
            case R.id.tv_start_answer:
                //记数字游戏开始答题
                tv_nine_title.setText("请回答下面问题");
                tv_longnum_num.setText("");
                ll_long_num_ques_fu.setVisibility(View.GONE);
                ll_longnum_question.setVisibility(View.VISIBLE);

                setLongNumQuestion(longqueitem);
                tv_start_answer.setVisibility(View.GONE);

                break;
            case R.id.tv_num_sure:
                //数字记忆答题确认按钮
                String inputnum = et_num_input.getText().toString().trim();
                List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                int size = answer.size();
                String answerstr = "";
                for (int i = 0;i<size;i++){
                    answerstr = answerstr+answer.get(i).getOpt_answer();
                }
                if (inputnum.equals(answerstr)){
                    //答案正确
                    myapp.scorenum = myapp.scorenum+4;
                }
                if (!"".equals(inputnum)){
                    ToastUtils.show("答案已提交");
                    handlerdelay.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            hideSoftKeyboard(MemoryTestActivity2.this);
                            currentposi = -1;
                            handlerdelay.removeCallbacksAndMessages(null);
                            codeLen = 0;
                            closeMediaplayer();
                            isvoice = false;
                            iscanvoice = false;
                            tv_rember_num_content.setText("");
                            voiceContent = "";
                            subjectitem++;
                            setQuestion(subjectitem);
                        }
                    },2000);

                }else{
                    ToastUtils.show("请先输入您的答案");
                }
                break;
            case R.id.tv_ci_sure:
                //词语句子答案确定
                String inputciyu = et_ci_input.getText().toString().trim();
                inputciyu = inputciyu.replace(" ","");
                List<AnswerQuesBean.DataBean.AnswerBean> answer1 = answerqueList.get(subjectitem).getAnswer();
                int size1 = answer1.size();
                String answerstr1 = "";
                for (int i = 0;i<size1;i++){
                    answerstr1 = answerstr1+answer1.get(i).getOpt_result();
                }
                answerstr1 = answerstr1.replace(" ","");
                int type = answerqueList.get(subjectitem).getType() - 1;
                if (type == 8 || type == 9){
                    if (inputciyu.equals(answerstr1)) {
                        myapp.scoreciyu = myapp.scoreciyu + 4;
                    }
                }else if (type == 17){
                    MyLog.e("单词",inputciyu+"输入    答案"+answerstr1);
                    if (inputciyu.equalsIgnoreCase(answerstr1)) {
                        myapp.scoredanci = myapp.scoredanci + 4;
                    }
                }
                if (!"".equals(inputciyu)){
                    ToastUtils.show("答案已提交");

                    handlerdelay.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            hideSoftKeyboard(MemoryTestActivity2.this);
                            currentposi = -1;
                            handlerdelay.removeCallbacksAndMessages(null);
                            codeLen = 0;
                            closeMediaplayer();
                            isvoice = false;
                            iscanvoice = false;
                            tv_rember_num_content.setText("");
                            voiceContent = "";
                            subjectitem++;
                            setQuestion(subjectitem);
                        }
                    },2000);


                }else{
                    ToastUtils.show("请先输入您的答案");
                }

                break;

        }

    }
    /**
     * 弹出退出页面搜索框
     */
    private void popbyexit() {

        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View popupWindow = layoutInflater.inflate(R.layout.popup_exit_course, null);

        TextView tv_cancle = popupWindow.findViewById(R.id.tv_cancle);
        TextView tv_sure = popupWindow.findViewById(R.id.tv_sure);
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopupWindowexit.dismiss();
            }
        });
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopupWindowexit.dismiss();
                finish();

            }
        });

        mPopupWindowexit = new PopupWindow(popupWindow, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        int mPopupWindowWidth = mPopupWindowexit.getWidth();
        int mPopupWindowHeight = mPopupWindowexit.getHeight();
        // 需要设置一下此参数，点击外边可消失
        mPopupWindowexit.setBackgroundDrawable(new BitmapDrawable());
        mPopupWindowexit.setOutsideTouchable(true);
        mPopupWindowexit.setTouchable(true);
        mPopupWindowexit.setFocusable(true); // pop 显示时， 不让外部 view 响应点击事件
        //防止被底部虚拟键挡住
        mPopupWindowexit.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        if (Build.VERSION.SDK_INT >= 24) { // Android 7.x中,PopupWindow高度为match_parent时,会出现兼容性问题,需要处理兼容性
            int Screenheightth = getWindowManager().getDefaultDisplay().getHeight();
            mPopupWindowexit.showAtLocation(tv_ciyu_content,
                    Gravity.BOTTOM,
                    0,
                    Screenheightth / 2);
//            Log.e("底部导航栏高度", utils.getNavigationBarHeight(context) + "    gaodu");

        } else {
            int Screenheightth = getWindowManager().getDefaultDisplay().getHeight();
            mPopupWindowexit.showAtLocation(tv_ciyu_content,
                    Gravity.BOTTOM,
                    0,
                    0);
        }
        mPopupWindowexit.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });

    }

    private String PATH = Environment.getExternalStorageDirectory().getPath() + "/huiduji_img/";

    private Bitmap getImagePath() {
        Bitmap bitmap = null;
        try {
            MyLog.e("找到图片路径", PATH + "/" + "drawpicxzj" + ".PNG" + "    图片名字");
            String asath = PATH + "/" + "drawpicxzj" + ".PNG";
            FileInputStream fs = new FileInputStream(asath);
            bitmap = BitmapFactory.decodeStream(fs);

            String adasd = "";

        } catch (Exception e) {
            e.printStackTrace();
            MyLog.e("获取图片路径", "抛异常");
        }
        return bitmap;

    }

    /**
     * 弹出搜索框收藏
     */
    private void popbygrade(View viewlayout) {

        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View popupWindow = layoutInflater.inflate(R.layout.layout_pop_bg, null);
        LinearLayout ll_pop_collect = popupWindow.findViewById(R.id.ll_pop_collect);
        LinearLayout ll_pop_exit = popupWindow.findViewById(R.id.ll_pop_exit);
        ll_pop_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mPopupResultWindow != null) {
                    if (mPopupResultWindow.isShowing()) {
                        mPopupResultWindow.dismiss();
                    }
                }
                collectData();
            }
        });
        ll_pop_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mPopupResultWindow != null) {
                    if (mPopupResultWindow.isShowing()) {
                        mPopupResultWindow.dismiss();
                    }
                }
                finish();
            }
        });

        mPopupResultWindow = new PopupWindow(popupWindow, ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
        int mPopupWindowWidth = mPopupResultWindow.getWidth();
        int mPopupWindowHeight = mPopupResultWindow.getHeight();
        // 需要设置一下此参数，点击外边可消失
        mPopupResultWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopupResultWindow.setOutsideTouchable(true);
        mPopupResultWindow.setTouchable(true);
        mPopupResultWindow.setFocusable(true); // pop 显示时， 不让外部 view 响应点击事件
        //防止被底部虚拟键挡住
        mPopupResultWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        if (Build.VERSION.SDK_INT >= 24) { // Android 7.x中,PopupWindow高度为match_parent时,会出现兼容性问题,需要处理兼容性
            int Screenheightth = getWindowManager().getDefaultDisplay().getHeight();
//            mPopupResultWindow.showAtLocation(ll_more_end,
//                    Gravity.BOTTOM,
//                    0,
//                    Screenheightth / 2);
            mPopupResultWindow.showAsDropDown(viewlayout, -100, 0);
//            Log.e("底部导航栏高度", utils.getNavigationBarHeight(context) + "    gaodu");

        } else {
            int Screenheightth = getWindowManager().getDefaultDisplay().getHeight();
//            mPopupResultWindow.showAtLocation(ll_more_end,
//                    Gravity.BOTTOM,
//                    0,
//                    0);
            mPopupResultWindow.showAsDropDown(viewlayout, -100, 0);
        }
        mPopupResultWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });

    }

    private void getData() {
        answerqueList.clear();
        String url = myapp.getWebConfig() + "/api/practices/index";
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("catelog_id", catelog_id);//课程章节id
        paramsMap.put("token", token);
        MyLog.e("课程题目", "catelog_id=" + catelog_id + "   token=" + token);
        RequestManager.getInstance(context).requestAsyn(url, RequestManager.TYPE_POST_FORM, paramsMap, new RequestManager.ReqCallBack() {
            @Override
            public void onReqSuccess(Object result) {
                MyLog.e("code--result", result.toString());
                Message msg = new Message();
                try {
                    JSONObject jsonObject = new JSONObject(result.toString());
                    if (jsonObject.getString("code").equals("0")) {
                        msg.obj = jsonObject.getString("msg");
                        msg.arg1 = 0;
                        handler.sendMessage(msg);
                        return;
                    }
                    JSONArray data = jsonObject.getJSONArray("data");
                    answerqueList = new Gson().fromJson(data.toString(), new TypeToken<List<AnswerQuesBean.DataBean>>() {
                    }.getType());
                    msg.arg1 = 2;
                    handler.sendMessage(msg);
                } catch (JSONException e) {
                    e.printStackTrace();
                    msg.arg1 = 1;
                    handler.sendMessage(msg);
                }
            }

            @Override
            public void onReqFailed(String errorMsg) {
                if (errorMsg.equals("未登录")) {
                    Message msg = new Message();
                    msg.arg1 = 11;
                    handler.sendMessage(msg);
                } else {
                    Message msg = new Message();
                    msg.arg1 = 12;
                    handler.sendMessage(msg);
                }
            }
        });
    }

    private void getJyData() {
        String url = myapp.getWebConfig() + "/api/practice/message";
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("catelog_id", catelog_id);
        RequestManager.getInstance(context).requestAsyn(url, RequestManager.TYPE_POST_FORM, paramsMap, new RequestManager.ReqCallBack() {
            @Override
            public void onReqSuccess(Object result) {
                MyLog.e("code--result", result.toString());
                Message msg = new Message();
                try {
                    JSONObject jsonObject = new JSONObject(result.toString());
                    if (jsonObject.getString("code").equals("0")) {
                        msg.obj = jsonObject.getString("msg");
                        msg.arg1 = 0;
                        handler.sendMessage(msg);
                        return;
                    }
                    JSONObject data = jsonObject.getJSONObject("data");
                    jyname = data.getString("name");
                    jycontent = data.getString("content");
                    msg.arg1 = 3;
                    handler.sendMessage(msg);
                } catch (JSONException e) {
                    e.printStackTrace();
                    msg.arg1 = 1;
                    handler.sendMessage(msg);
                }
            }

            @Override
            public void onReqFailed(String errorMsg) {
                if (errorMsg.equals("未登录")) {
                    Message msg = new Message();
                    msg.arg1 = 11;
                    handler.sendMessage(msg);
                } else {
                    Message msg = new Message();
                    msg.arg1 = 12;
                    handler.sendMessage(msg);
                }
            }
        });
    }

    private void getShareData() {
        String url = myapp.getWebConfig() + "/api/Leesign/signInfo";
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("catelog_id", catelog_id);
        paramsMap.put("course_id", course_id);
        paramsMap.put("token", token);
        RequestManager.getInstance(context).requestAsyn(url, RequestManager.TYPE_POST_FORM, paramsMap, new RequestManager.ReqCallBack() {
            @Override
            public void onReqSuccess(Object result) {
                MyLog.e("code--result", result.toString());
                Message msg = new Message();
                try {
                    JSONObject jsonObject = new JSONObject(result.toString());
                    if (jsonObject.getString("code").equals("0")) {
                        msg.obj = jsonObject.getString("msg");
                        msg.arg1 = 0;
                        handler.sendMessage(msg);
                        return;
                    }
                    JSONObject data = jsonObject.getJSONObject("data");
                    studyscore = data.getString("num");
                    dakaday = data.getString("sign_num");
                    studyday = data.getString("study_num");
                    msg.arg1 = 5;
                    handler.sendMessage(msg);
                } catch (JSONException e) {
                    e.printStackTrace();
                    msg.arg1 = 1;
                    handler.sendMessage(msg);
                }
            }

            @Override
            public void onReqFailed(String errorMsg) {
                if (errorMsg.equals("未登录")) {
                    Message msg = new Message();
                    msg.arg1 = 11;
                    handler.sendMessage(msg);
                } else {
                    Message msg = new Message();
                    msg.arg1 = 12;
                    handler.sendMessage(msg);
                }
            }
        });
    }

    private void collectData() {
        String url = myapp.getWebConfig() + "/api/collect/collect";
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("catelog_id", catelog_id);//课程章节id
        paramsMap.put("course_id", course_id);//课程id
        paramsMap.put("token", token);
        RequestManager.getInstance(context).requestAsyn(url, RequestManager.TYPE_POST_FORM, paramsMap, new RequestManager.ReqCallBack() {
            @Override
            public void onReqSuccess(Object result) {
                MyLog.e("code--result", result.toString());
                Message msg = new Message();
                try {
                    JSONObject jsonObject = new JSONObject(result.toString());
                    if (jsonObject.getString("code").equals("0")) {
                        msg.obj = jsonObject.getString("msg");
                        msg.arg1 = 0;
                        handler.sendMessage(msg);
                        return;
                    }

                    msg.arg1 = 6;
                    handler.sendMessage(msg);
                } catch (JSONException e) {
                    e.printStackTrace();
                    msg.arg1 = 1;
                    handler.sendMessage(msg);
                }
            }

            @Override
            public void onReqFailed(String errorMsg) {
                if (errorMsg.equals("未登录")) {
                    Message msg = new Message();
                    msg.arg1 = 11;
                    handler.sendMessage(msg);
                } else {
                    Message msg = new Message();
                    msg.arg1 = 12;
                    handler.sendMessage(msg);
                }
            }
        });
    }

    public Handler handler = new Handler() {

        @SuppressLint("HandlerLeak")
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.arg1) {
                case 0:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }
                    String obj = (String) msg.obj;
                    ToastUtils.show(obj);
                    if (obj.contains("暂未录入")) {
                        finish();
                    }
                    break;
                case 1:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }

                    break;
                case 2:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }
                    int size = answerqueList.size();
                    for (int i = 0; i < size; i++) {
                        String prompt_file = answerqueList.get(i).getPrompt_file();
                        videourllist.add(prompt_file);
                        List<String> video_url = answerqueList.get(i).getVideo_url();
                        videourllist.addAll(video_url);
                    }
                    new DownUtil(videourllist,context);
//                    new MyThread(2,context,videourllist).start();
                    break;
                case 3:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }
                    tv_jyname.setText(jyname);
                    tv_jycontent.setText(jycontent);

                    break;
                case 4:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }
                    break;
                case 5:
                    tv_score.setText(studyscore);
                    tv_study_day.setText(studyday);
                    tv_daka_day.setText(dakaday);
                    break;
                case 6:
                    if (mPopupResultWindow != null) {
                        if (mPopupResultWindow.isShowing()) {
                            mPopupResultWindow.dismiss();
                        }
                    }
                    ToastUtils.show("收藏成功");
                    break;
                case 11:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }
                    sharedPreferences.edit().putString("user_id","").commit();
                    sharedPreferences.edit().putString("username","").commit();
                    sharedPreferences.edit().putString("nickname","").commit();
                    sharedPreferences.edit().putString("mobile","").commit();
                    sharedPreferences.edit().putString("avatar","").commit();
                    sharedPreferences.edit().putString("score","").commit();
                    sharedPreferences.edit().putString("student_id","").commit();
                    sharedPreferences.edit().putString("is_bind_wx","").commit();
                    sharedPreferences.edit().putString("token","").commit();
                    sharedPreferences.edit().putString("is_agent","").commit();
                    sharedPreferences.edit().putString("vip_expire","").commit();
                    sharedPreferences.edit().putString("is_vip","").commit();
                    finish();
                    break;
                case 12:
                    if (customProgressDialog != null) {
                        if (customProgressDialog.isShowing()) {
                            customProgressDialog.dismiss();
                        }
                    }
                    break;
            }
        }
    };
    /**
     * 提供（相对）精确的除法运算。当发生除不尽的情况时，由scale参数指
     * 定精度，以后的数字四舍五入。
     * @param v1 被除数
     * @param v2 除数
     * @param scale 表示表示需要精确到小数点以后几位。
     * @return 两个参数的商
     */
    public static double div(double v1,double v2, int scale) {
        if (scale < 0) {
            throw new IllegalArgumentException(
                    "The scale must be a positive integer or zero");
        }
        BigDecimal b1 = new BigDecimal(Double.toString(100));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    private void setQuestion(int i) {
        iscanvoice = true;
        int listsize = answerqueList.size();
        double i1 = div(100,listsize,3);
        int i2 = i+1;
        double i3 = i1 * i2;
        MyLog.e("进度条",i3+"=i3   进度条  i1="+i1+"   i2="+i2);
        pb_main_downloadone.setProgress((int) i3);
        if (i == listsize - 1) {
            pb_main_downloadone.setProgress(100);
        }


        if (i > listsize - 1) {
//            ToastUtils.show("已经是最后一题了");
            hideSoftKeyboard(MemoryTestActivity2.this);
            ll_end_memory.setVisibility(View.VISIBLE);
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.GONE);
            ll_subject_content2.setVisibility(View.GONE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
//            int scoreciyu = myapp.scoreciyu;
            tv_score_ciyu.setText(myapp.scoreciyu+"");
            tv_score_num.setText(myapp.scorenum+"");
            tv_score_kanji.setText(myapp.scorekanji+"");
            tv_score_tingji.setText(myapp.scoretingji+"");
            tv_score_danci.setText(myapp.scoredanci+"");
            int totalscore = myapp.scoreciyu+myapp.scorenum+myapp.scorekanji+myapp.scoretingji+myapp.scoredanci;
            tv_score_total.setText(totalscore+"");

//            initMusicplay("a21", "", "");
            return;
        }
        hideSoftKeyboard(MemoryTestActivity2.this);
        //类型:0=图形记忆--选择题 ,1=点的记忆--选择题,2=九宫格心形,3=九宫格星星,4=九宫格笑脸,5=九宫格数字,6=看记数字-正背倒背,7=听记数字-正背倒背,8=课内词语跟读,9=课外词语跟读,10=课外语段跟读,11=听力-选择题
        subjectType = answerqueList.get(i).getType();
        subjectType = subjectType - 1;
//        课程类型:1=选择题,2=九宫格,3=九宫格数字,4=看记数字-正背倒背,5=听记数字-正背倒背,6=词语跟读,7听力-选择题
        splashtypes = answerqueList.get(i).getTypes();
        String showtime = answerqueList.get(i).getSecond();
        if ("".equals(showtime) || showtime == null) {
            //如果获取时间错误，设置默认时间2秒
            if ("6".equals(subjectType) || "14".equals(subjectType)) {
                showtime = "0.5";
            } else {
                showtime = "2";
            }
        }
        codeLen = Float.parseFloat(showtime);
        codeLentemp = Float.parseFloat(showtime);
        int grid = answerqueList.get(i).getGrid();
        int id = answerqueList.get(i).getId();
        boolean isaddid = true;
        for (int b = 0; b < drawids.size(); b++) {
            String s = drawids.get(b);
            if (s.equals(id + "")) {
                isaddid = false;
                break;
            }
        }
        if (isaddid) {
            drawids.add(id + "");
        }
        isaddflag = isaddid;
        //课程标题
        String course_list_name = answerqueList.get(i).getCourse_list_name();
        //图片题型得图片
        String imgimg = answerqueList.get(i).getImage();
        String title_desc = answerqueList.get(i).getTitle_desc();
        //答案
        List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(i).getAnswer();
        int answersize = answer.size();
        if ("1".equals(splashtypes)) {
            //课程类型:1=选择题
            initDefault();
            ll_see_img_question.setVisibility(View.GONE);
            tv_select_answerA.setText("");
            tv_select_answerB.setText("");
            tv_select_answerC.setText("");
            img_answerA.setVisibility(View.GONE);
            img_answerB.setVisibility(View.GONE);
            img_answerC.setVisibility(View.GONE);
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","32");//        initMusicplay("a08", subjectType + "", "");initMusicplay("a08", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("32", subjectType + "");
            }


        } else if ("2".equals(splashtypes)) {
            //课程类型:2=九宫格

            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) gridview_ninetable.getLayoutParams();
            int width = screenwidth - DensityUtil.dip2px(context, 104);
            if (grid == 1) {
                gridview_ninetable.setNumColumns(3);
                int realwidth = width - DensityUtil.dip2px(context, 18);
                itemwidth = realwidth / 3;
            } else if (grid == 2) {
                gridview_ninetable.setNumColumns(4);
                int realwidth = width - DensityUtil.dip2px(context, 22);
                itemwidth = realwidth / 4;
            } else {
                gridview_ninetable.setNumColumns(3);
                int realwidth = width - DensityUtil.dip2px(context, 18);
                itemwidth = realwidth / 3;
            }
            layoutParams.width = width;
            layoutParams.height = width;
            gridview_ninetable.setLayoutParams(layoutParams);
//            if (nineTableAdapter == null) {
            nineTableAdapter = new NineTableAdapter(context, answerqueList.get(i).getAnswer());
            gridview_ninetable.setAdapter(nineTableAdapter);
//            }
            initDefault();
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","4");//        initMusicplay("a26", subjectType + "", "");initMusicplay("a26", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("4", subjectType + "");
            }


        } else if ("3".equals(splashtypes)) {
            //课程类型:3=九宫格数字
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) gridview_ninetable.getLayoutParams();
            int width = screenwidth - DensityUtil.dip2px(context, 104);
            if (grid == 1) {
                gridview_ninetable.setNumColumns(3);
                int realwidth = width - DensityUtil.dip2px(context, 18);
                itemwidth = realwidth / 3;
            } else if (grid == 2) {
                gridview_ninetable.setNumColumns(4);
                int realwidth = width - DensityUtil.dip2px(context, 22);
                itemwidth = realwidth / 4;
            } else {
                gridview_ninetable.setNumColumns(3);
                int realwidth = width - DensityUtil.dip2px(context, 18);
                itemwidth = realwidth / 3;
            }
            layoutParams.width = width;
            layoutParams.height = width;
            gridview_ninetable.setLayoutParams(layoutParams);
            initDefault();
//            if (nineTableNunAdapter == null) {
            nineTableNunAdapter = new NineTableNumAdapter(context, answerqueList.get(i).getAnswer());
            gridview_ninetable.setAdapter(nineTableNunAdapter);
//            }
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
//                tv_nine_title.setText("请2秒记忆以下图形所在位置");
                setMusicUrl(subjectType+"", "","5");//        initMusicplay("a06", subjectType + "", "");initMusicplay("a06", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("5", subjectType + "");
            }
        } else if ("4".equals(splashtypes)) {
            //课程类型:4=看记数字-正背倒背
            initDefault();
            numberstr = "";
            for (int m = 0; m < answersize; m++) {
                String opt = answer.get(m).getOpt_answer();
                numberstr = numberstr + opt;
            }
            numberstrback = "";
            for (int m = answersize - 1; m > -1; m--) {
                String opt = answer.get(m).getOpt_answer();
                numberstrback = numberstrback + opt;
            }
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","6");//       initMusicplay("a10", subjectType + "", ""); initMusicplay("a10", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("6", subjectType + "");
            }

        } else if ("5".equals(splashtypes)) {
            //课程类型:5=听记数字-正背倒背
            initDefault();
//            tv_splash_tv.setText("听记数字记忆");//引导页标题
//            initMusicplay("a10", subjectType);

            numberstr = "";
            for (int m = 0; m < answersize; m++) {
                String opt = answer.get(m).getOpt_answer();
                numberstr = numberstr + opt;
            }
            numberstrback = "";
            for (int m = answersize - 1; m > -1; m--) {
                String opt = answer.get(m).getOpt_answer();
                numberstrback = numberstrback + opt;
            }
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","8");//       initMusicplay("a29", subjectType + "", "");initMusicplay("a29", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("8", subjectType + "");
            }

        } else if ("6".equals(splashtypes)) {
            //课程类型:6=词语跟读
            initDefault();
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                if ("8".equals(subjectType+"") ){
                    tv_splash_tv.setText(title_desc);//引导页标题
//                    initMusicplay("a15", subjectType + "", "");
                }else if ("9".equals(subjectType+"") ){
                    tv_splash_tv.setText(title_desc);//引导页标题
                    setMusicUrl(subjectType+"", "","9");//      initMusicplay("a37", subjectType + "", "");initMusicplay("a37", subjectType + "", "");
                }else if ("11".equals(subjectType+"")){
                    tv_splash_tv.setText(title_desc);//引导页标题
                    setMusicUrl(subjectType+"", "","11");//      initMusicplay("a38", subjectType + "", "");initMusicplay("a38", subjectType + "", "");
                }else if ("10".equals(subjectType+"")){
                    tv_splash_tv.setText(title_desc);//引导页标题
                    setMusicUrl(subjectType+"", "","10");//      initMusicplay("a39", subjectType + "", "");initMusicplay("a39", subjectType + "", "");
                }else if ("18".equals(subjectType+"")){
                    tv_splash_tv.setText(title_desc);//引导页标题
                    setMusicUrl(subjectType+"", "","12");//      initMusicplay("a39", subjectType + "", "");
                }else if ("17".equals(subjectType+"") ){
                    //单词记忆
                    tv_splash_tv.setText(title_desc );//引导页标题
//                    initMusicplay("", subjectType + "", "");
                    setMusicUrl(subjectType+"", "","");
                }

            } else {
                //无需显示引导页，直接显示题目
                if ("8".equals(subjectType+"") ){
                    setViewData("a15", subjectType + "");
                }else if ("9".equals(subjectType+"") ){
                    setViewData("9", subjectType + "");
                }else if ("11".equals(subjectType+"")){
                    setViewData("11", subjectType + "");
                }else if ("10".equals(subjectType+"")){
                    setViewData("10", subjectType + "");
                }else if ("18".equals(subjectType+"")){
                    setViewData("12", subjectType + "");
                }else if ("17".equals(subjectType+"") ){
                    setViewData("a15", subjectType + "");
                }
            }
        } else if ("7".equals(splashtypes)) {
            //课程类型:7听力-选择题

        } else if ("8".equals(splashtypes)) {
            //类型:8画图
            initDefault();
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_draw_pic.setVisibility(View.VISIBLE);
            tv_draw_title.setText(course_list_name);
            GlideUtils.loadImage(context, imgimg, img_stand_pic);
            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (codeLen > 0) {
                        int atime = (int) codeLen;
                        String str = "请在" + atime + "s" + "内记忆以下图形";//请在12S内记忆以下图形
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String wei = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 2, 2 + wei.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        codeLen--;

                        if (isaddflag) {
                            ll_draw_btn.setVisibility(View.GONE);
                        } else {
                            ll_draw_btn.setVisibility(View.VISIBLE);
                            tv_draw_now.setVisibility(View.VISIBLE);
                            tv_seeimg_try.setVisibility(View.GONE);
                            tv_draw_ok.setVisibility(View.GONE);
                        }

                        handlerdelay.postDelayed(this, 1000);
                    } else if (codeLen == 0 || codeLen < 0) {
                        int atime = (int) codeLen;
                        String str = "请在" + atime + "s" + "记忆以下图形";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String wei = atime + "";
                        ll_draw_btn.setVisibility(View.VISIBLE);
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 2 + wei.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        handler.removeCallbacks(this);
                        codeLen = codeLentemp;

                        ll_draw_btn.setVisibility(View.VISIBLE);
                        tv_draw_now.setVisibility(View.GONE);
                        tv_seeimg_try.setVisibility(View.VISIBLE);
                        tv_draw_ok.setVisibility(View.VISIBLE);

                        tv_nine_title.setText("请画出刚才所看到的图形");
                        rl_draw_subject.setVisibility(View.GONE);
                        rl_draw.setVisibility(View.VISIBLE);
                    }
                }
            }, 0);//2秒后执行Runnable中的run方法
        } else if ("9".equals(splashtypes)) {
            //数字滚动--闪记
            initDefault();
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","7");//      initMusicplay("a32", subjectType + "", "");initMusicplay("a32", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("7", subjectType + "");
            }
        } else if ("10".equals(splashtypes)) {
            //看记数字
            initDefault();
            numberstr = "";
            for (int m = 0; m < answersize; m++) {
                String opt = answer.get(m).getOpt_answer();
                numberstr = numberstr + opt;
            }
            numberstrback = "";
            for (int m = answersize - 1; m > -1; m--) {
                String opt = answer.get(m).getOpt_answer();
                numberstrback = numberstrback + opt;
            }
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","6");//       initMusicplay("a10", subjectType + "", ""); initMusicplay("a10", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("6", subjectType + "");
            }

        } else if ("11".equals(splashtypes)) {
            //长串数字
            initDefault();
            if (ll_splash.getVisibility() == View.VISIBLE) {
                //引导页显示播报题目类型介绍,音频播报完之后，直接显示题目
                tv_splash_tv.setText(title_desc);//引导页标题
                setMusicUrl(subjectType+"", "","2");//       initMusicplay("a33", subjectType + "", "");initMusicplay("a33", subjectType + "", "");
            } else {
                //无需显示引导页，直接显示题目
                setViewData("2", subjectType + "");
            }
        } else {
            //新增题型先跳过
            subjectitem++;
            setQuestion(subjectitem);
        }

    }

    private List<String> recordlist = new ArrayList<>();

    public void initDefault() {

        if (timer == null) {
            timer = new Timer();
        }
        if (timer != null && mTask != null) {
            mTask.cancel();
        }

        tv_ninetable_desc.setVisibility(View.GONE);
        tv_remark.setVisibility(View.GONE);//九宫格答案评语
        ll_subject_content.setVisibility(View.GONE);//各种题型的父布局
        ll_subject_content2.setVisibility(View.GONE);//各种题型的父布局
        ll_ciyu_jiaocheng.setVisibility(View.GONE);
        ll_nine_table.setVisibility(View.GONE);//九宫格
        ll_listener_rember.setVisibility(View.GONE);//听记
        ll_rember_num.setVisibility(View.GONE);//倒背正背数字
        ll_see_img.setVisibility(View.GONE);//看图记忆
        ll_draw_pic.setVisibility(View.GONE);//画画
        rl_shan_num.setVisibility(View.GONE);//数字滚动
        ll_num_answer.setVisibility(View.GONE);//数字记忆案题布局
        ll_ci_answer.setVisibility(View.GONE);//词语答题布局
        img_record.setVisibility(View.GONE);//录音按钮隐藏，句子看记听记显示
        et_ci_input.setText("");
        et_num_input.setText("");
        tv_shannum_num.setText("");
        ll_shan_content.setVisibility(View.GONE);
        rl_long_num.setVisibility(View.GONE);
        ll_longnum_question.setVisibility(View.GONE);
        clicknineitems.clear();
        tv_listener_rember_title.setText("");
        tv_listener_rember.setText("");
        voiceContent = "";

        ll_selectA.setBackgroundResource(R.drawable.white_re);
        tv_select_answerA.setTextColor(getResources().getColor(R.color.color333));
        ll_selectB.setBackgroundResource(R.drawable.white_re);
        tv_select_answerB.setTextColor(getResources().getColor(R.color.color333));
        ll_selectC.setBackgroundResource(R.drawable.white_re);
        tv_select_answerC.setTextColor(getResources().getColor(R.color.color333));
        boolean isshow = true;

        String typwstring = splashtypes;
        if ("8".equals(subjectType+"") || "9".equals(subjectType+"")|| "11".equals(subjectType+"") || "17".equals(subjectType)){
            typwstring = "a"+subjectType;
        }else if ("10".equals(subjectType+"") || "18".equals(subjectType+"")){
            typwstring = "a10";
        }

        if ("".equals(splashtypeslast)) {
            ll_splash.setVisibility(View.VISIBLE);//题目引导页
            splashtypeslast = typwstring;
        } else {
            if (splashtypeslast.equals(typwstring)) {
                //当前题目和上一个题目是同一个类型，引导页不需要显示，直接显示题目
                ll_splash.setVisibility(View.GONE);//题目引导页隐藏
            } else {
                //当前题目和上一个题目不是同一个类型，引导页需要显示

                for (int i = 0; i < recordlist.size(); i++) {
                    String s = recordlist.get(i);
                    if (s.equals(typwstring)) {
                        isshow = false;
                        break;
                    }
                }
                if (isshow) {
                    ll_splash.setVisibility(View.VISIBLE);//题目引导页隐藏
                } else {
                    ll_splash.setVisibility(View.GONE);//题目引导页隐藏
                }
            }
        }
        splashtypeslast = typwstring;
        if (isshow) {
            recordlist.add(typwstring);
        }


    }

    /**
     * 初始化播放 初始化完成 就开始播放
     *
     * @param music
     */
    public void initMusicplay(String music, String type, String onlinemusic,String musicId) { //播放音乐函数

        stopPlay();
        try {
            mediaPlayer = new MediaPlayer();
            if ("".equals(onlinemusic)) {
                File file = new File("/storage/emulated/0/test_music/", music + ".mp3");

                if (file.exists()) {
                    MyLog.e("打印路径", file.getPath() + "   打印路径");
                    mediaPlayer.setDataSource(file.getPath());
                }
            } else {
                String userInfo = getUserInfo(onlinemusic);
                if (userInfo != null || !"".equals(userInfo)) {
                    File file = new File("/storage/emulated/0/test_music/", userInfo + ".mp3");
                    if (file.exists()) {
                        MyLog.e("打印路径", file.getPath() + "   打印路径");
                        mediaPlayer.setDataSource(file.getPath());
                    } else {
//                        ToastUtils.show("音频文件路径未找到");
                        MyLog.e("打印路径", "   文件不存在");
                        mediaPlayer.setDataSource(onlinemusic);  //添加数据源
                    }
                } else {
                    mediaPlayer.setDataSource(onlinemusic);  //添加数据源
                }
            }
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);   //设置流媒体的类型，AudioManager可以修改系统的情景模式为音乐 可以后台播放

            mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {//准备完毕后调用
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    mediaPlayer.start();//开始播放音乐
                }
            });
            mediaPlayer.prepareAsync();//异步准备
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {//放完一首歌后调用
                @Override
                public void onCompletion(MediaPlayer mp) {
                    mediaPlayer.release();
                    mediaPlayer = null;
                    MyLog.e("音频播放完毕", "音频播放完毕");
                    if ("1".equals(musicId)) {
                        //课程开始页面音频播放完毕，开始第一个题型的引导页
                        rl_start.setVisibility(View.GONE);
                        ll_splash.setVisibility(View.VISIBLE);

                        if (!isintosplash) {
                            if (answerqueList.size() > 0) {
                                isintosplash = true;
                                subjectitem = 0;
                                setQuestion(0);
                            }
                        }
                    } else if ("32".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("4".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("5".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("6".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("15".equals(musicId)) {
                        iscanvoice = true;
                        MyLog.e("是否可以录音", iscanvoice + "   1374行");
                        MyLog.e("音频播放完毕", "可以录音27" + iscanvoice);
                    } else if ("16".equals(musicId)) {
                        iscanvoice = true;
                        MyLog.e("是否可以录音", iscanvoice + "   1378行");
                        MyLog.e("音频播放完毕", "可以录音28" + iscanvoice);
                    } else if ("8".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("a15".equals(musicId) || "9".equals(musicId)|| "11".equals(musicId)|| "10".equals(musicId)|| "12".equals(musicId)) {
                        setViewData(musicId, type);  //a37=9 a38=11 a39=10  12
                    } else if ("7".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("2".equals(musicId)) {
                        setViewData(musicId, type);
                    } else if ("a21".equals(musicId)) {
                        ll_end_daka.setVisibility(View.VISIBLE);
                        ll_subject_content.setVisibility(View.GONE);
                        ll_subject_content2.setVisibility(View.GONE);
                        ll_ciyu_jiaocheng.setVisibility(View.GONE);
                    }

                    if (!"".equals(onlinemusic)) {
                        if ("8".equals(subjectType + "") || "9".equals(subjectType + "")) {

                        //课内词语课外词语教程音频播放完毕，还是显示题目

                        ll_subject_content.setVisibility(View.VISIBLE);
                        ll_subject_content2.setVisibility(View.VISIBLE);
                        ll_ciyu_jiaocheng.setVisibility(View.GONE);
                        ll_listener_rember.setVisibility(View.VISIBLE);
                        if (nineTableAdapter != null) {
                            nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
                        }
                        //听记的内容呈现出来

                        String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
                        String title = answerqueList.get(subjectitem).getTitle();
                        tv_listener_rember_title.setText(title);
                        medialists.clear();
//                        unitlists.clear();

//                    8=课内词语跟读,9=课外词语跟读,10=课外语段跟读-看记,11=课外语段跟读-听记

//                        tv_nine_title.setText("请朗读下面的内容");
                        //课内词语  课外词语
                        List<String> videourls = answerqueList.get(subjectitem).getVideo_url();
                        for (int i = 0; i < videourls.size(); i++) {
                            String url = videourls.get(i);
                            MyLog.e("词语跟读", url + "   词语跟读");
                            medialists.add(url);
                        }
                        MyLog.e("changeplay", "1864行");
                        changePlay(0, "1");//第二个参数，0代表是数字听力，1代表是词语跟读
                        if ("8".equals(subjectType + "")) {
                            tv_nine_title.setText(getResources().getString(R.string.keneiciyu));
                        } else if ("9".equals(subjectType + "")) {
                            tv_nine_title.setText(getResources().getString(R.string.kewaiciyu));
                        }
                    }
                    }


                }
            });
        } catch (Exception e) {
            String message = e.getMessage();
            e.printStackTrace();
//                EventBus.getDefault().post(new PushMsgEvent(message, message));
        }


    }

    public void closeMediaplayer() {
        try {
            if (mediaPlayer != null) {
                mediaPlayer.stop();
                mediaPlayer.release();
                mediaPlayer = null;
                /*if (mediaPlayer.isPlaying()) {
                    mediaPlayer.release();
                }*/
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    //停止播放
    public static void stopPlay() {
        try {
            if (mediaPlayer != null) {
                mediaPlayer.pause();
//            mediaPlayer.seekTo(0);
//            mediaPlayer.stop();
                mediaPlayer.reset();
                mediaPlayer.release();
                mediaPlayer = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    float codeLen = 6;
    float codeLentemp = 6;
    int temprightitem = -1;

    public void setViewData(String voicetype, String type) {
        if ("1".equals(voicetype)) {
            //课程开始页面
            tv_nine_title.setText("请2秒记忆以下图形所在位置");

            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();
            }
            if (nineTableNunAdapter != null) {
                nineTableNunAdapter.setGone();
            }
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_nine_table.setVisibility(View.VISIBLE);

            nineTableAdapter.setData(answerqueList.get(subjectitem).getAnswer(), type, itemwidth);

            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    /**
                     *要执行的操作
                     */
//                    initMusicplay("a02", type, "");//已去掉
                    tv_nine_title.setText("请回忆刚才所记忆的图形位置");
                    tv_ninetable_desc.setVisibility(View.GONE);
                    if (nineTableAdapter != null) {
                        nineTableAdapter.setGone();
                    }
                    isNineTableClick = true;
                }
            }, 2000);//2秒后执行Runnable中的run方法

        } else if ("a02".equals(voicetype)) {

        } else if ("a03".equals(voicetype)) {

        } else if ("a04".equals(voicetype)) {

        } else if ("a05".equals(voicetype)) {

        } else if ("5".equals(voicetype)) {
            //九宫格数字
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_nine_table.setVisibility(View.VISIBLE);
            if (nineTableNunAdapter != null) {
                nineTableNunAdapter.setGone();
                nineTableNunAdapter.setData(answerqueList.get(subjectitem).getAnswer(), itemwidth);
            }
            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    /**
                     *要执行的操作
                     */
                    if (codeLen > 0) {
                        int atime = (int) codeLen;
                        String str = "请" + atime + "s" + "记忆以下图形所在位置";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串 1-3 1  1-4 2
                        String astime = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 1 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        codeLen--;

                        handlerdelay.postDelayed(this, 1000);
                    } else if (codeLen == 0 || codeLen < 0) {
                        int atime = (int) codeLen;
                        String str = "请" + atime + "s" + "记忆以下图形所在位置";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String astime = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 1 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        handler.removeCallbacks(this);
                        codeLen = codeLentemp;
//                        initMusicplay("a07", type, "");
                        tv_nine_title.setText("请回忆刚才所记忆的图形位置");
                        tv_ninetable_desc.setVisibility(View.GONE);
                        nineTableNunAdapter.setGone();
                        isNineTableClick = true;
                    }
                }
            }, 0);//2秒后执行Runnable中的run方法
        } else if ("a07".equals(voicetype)) {

        } else if ("32".equals(voicetype)) {
            //图片选择题
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) img_see_img_content.getLayoutParams();
            if ("1".equals(type)) {
                layoutParams.height = DensityUtil.dip2px(context, 270);
            } else if ("0".equals(type)) {
                layoutParams.height = DensityUtil.dip2px(context, 178);
            }
            img_see_img_content.setLayoutParams(layoutParams);
            //图片题型得图片
            String imgimg = answerqueList.get(subjectitem).getImage();
            //标题
            String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            String title = answerqueList.get(subjectitem).getTitle();
            List<String> video_url = answerqueList.get(subjectitem).getVideo_url();
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_see_img.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
//            tv_nine_title.setText("请5s内记忆以下图形");
            img_see_img_content.setVisibility(View.VISIBLE);
            GlideUtils.loadRoundCircleImage(context, imgimg, img_see_img_content);

            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    /**
                     *要执行的操作
                     */

                    if (codeLen > 0) {

                        int atime = (int) codeLen;
                        String str = "请" + atime + "s" + "内记忆以下图形";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String astime = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 1 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        codeLen--;

                        handlerdelay.postDelayed(this, 1000);
                    } else if (codeLen == 0 || codeLen < 0) {
                        int atime = (int) codeLen;
                        String str = "请" + atime + "s" + "内记忆以下图形";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String astime = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 1 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        handler.removeCallbacks(this);
                        codeLen = codeLentemp;

                        tv_nine_title.setText("请回忆上图内容并回答以下问题");
                        String s = "";
                        if (video_url.size() > 0) {
                            s = video_url.get(0);
                        }
                        setMusicUrl(type, s,"7");//      initMusicplay("a25", type, s);initMusicplay("a25", type, s);
                        ll_select_item.removeAllViews();
                        int size = answer.size();

                        for (int i = 0; i < size; i++) {
                            View view = View.inflate(context, R.layout.item_selectitem, null);
                            LinearLayout ll_select = view.findViewById(R.id.ll_select);
                            TextView tv_select_answer = view.findViewById(R.id.tv_select_answer);
                            ImageView img_answer = view.findViewById(R.id.img_answer);
                            tv_select_answer.setText(answer.get(i).getOpt_answer());
                            String opt_result = answer.get(i).getOpt_result();
                            if ("0".equals(opt_result)) {
                                img_answer.setImageResource(R.mipmap.icon_error_x);
                            } else {
                                temprightitem = i;
                                img_answer.setImageResource(R.mipmap.icon_right_g);
                            }
                            ll_select.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if ("0".equals(opt_result)) {
                                        ll_select.setBackgroundResource(R.drawable.red_bg);
                                        img_answer.setVisibility(View.VISIBLE);
                                        tv_select_answer.setTextColor(getResources().getColor(R.color.colorfff));
                                        if (temprightitem != -1) {
                                            LinearLayout viewById = ll_select_item.getChildAt(temprightitem).findViewById(R.id.ll_select);
                                            TextView tv_select_answer = ll_select_item.getChildAt(temprightitem).findViewById(R.id.tv_select_answer);
                                            ImageView img_answer = ll_select_item.getChildAt(temprightitem).findViewById(R.id.img_answer);
                                            viewById.setBackgroundResource(R.drawable.green_answer_bg);
                                            img_answer.setVisibility(View.VISIBLE);
                                            tv_select_answer.setTextColor(getResources().getColor(R.color.colorfff));
                                        }
                                        ToastUtils.show("没关系的，继续努力");
                                        setMusicUrl(subjectType+"", "","30");//        initMusicplay("a04", subjectType + "", "");initMusicplay("a04", subjectType + "", "");
                                    } else {
                                        ll_select.setBackgroundResource(R.drawable.green_answer_bg);
                                        img_answer.setVisibility(View.VISIBLE);
                                        tv_select_answer.setTextColor(getResources().getColor(R.color.colorfff));
                                        ToastUtils.show("全部正确，你的回答真棒！");
                                        setMusicUrl(subjectType+"", "","14");//        initMusicplay("a03", subjectType + "", "");initMusicplay("a03", subjectType + "", "");
                                    }
                                }
                            });
                            ll_select_item.addView(view);
                        }


                        tv_ninetable_desc.setVisibility(View.GONE);
                        img_see_img_content.setVisibility(View.GONE);
                        ll_see_img_question.setVisibility(View.VISIBLE);
                        if (nineTableNunAdapter != null) {
                            nineTableNunAdapter.setGone();
                        }
                        isNineTableClick = true;
                        tv_see_img_question_title.setText(course_list_name);
                        tv_select_answerA.setText(answer.get(0).getOpt_answer());
                        if ("0".equals(answer.get(0).getOpt_result())) {
                            img_answerA.setImageResource(R.mipmap.icon_error_x);
                        } else {
                            img_answerA.setImageResource(R.mipmap.icon_right_g);
                        }
                        tv_select_answerB.setText(answer.get(1).getOpt_answer());
                        if ("0".equals(answer.get(1).getOpt_result())) {
                            img_answerB.setImageResource(R.mipmap.icon_error_x);
                        } else {
                            img_answerB.setImageResource(R.mipmap.icon_right_g);
                        }
                        tv_select_answerC.setText(answer.get(2).getOpt_answer());
                        if ("0".equals(answer.get(2).getOpt_result())) {
                            img_answerC.setImageResource(R.mipmap.icon_error_x);
                        } else {
                            img_answerC.setImageResource(R.mipmap.icon_right_g);
                        }
                    }
                }
            }, 0);//2秒后执行Runnable中的run方法

        } else if ("a09".equals(voicetype)) {

        } else if ("6".equals(voicetype)) {
            //看记数字倒背正背
            tv_nine_title.setText("请按顺序背出所看到的数字");
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_rember_num.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
            if ("4".equals(splashtypes)) {
                //看记数字----单个数字单个数字显示
                iscancle = false;
                startindex = -1;
                endindex = -1;
                if (timer == null) {
                    timer = new Timer();
                }
                if (timer != null && mTask != null) {
                    mTask.cancel();
                }
                mTask = new MyTimerTask();
                long timesee = (long) (codeLen * 1000);
                timer.schedule(mTask, 0, timesee);
            } else if ("5".equals(splashtypes)) {
                //听记数字
                setMusicUrl(subjectType+"", "","8");//        initMusicplay("a11", subjectType + "", "");initMusicplay("a11", subjectType + "", "");
            } else if ("10".equals(splashtypes)) {
                //看记数字---全部显示完
                List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                int size = answer.size();
                String str = "";
                for (int m = 0; m < size; m++) {
                    str = str + answer.get(m).getOpt_answer();
                }
                tv_rember_num_content.setVisibility(View.VISIBLE);
                tv_rember_num_content.setTextColor(getResources().getColor(R.color.color333));
                tv_rember_num_content.setText(str);
                MyLog.e("看记数字全部显示", str + "   数字");
                handlerdelay.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (codeLen > 0) {
                            int atime = (int) codeLen;
                            String str = "请在" + atime + "s" + "内记忆以下数字";
                            SpannableStringBuilder style = new SpannableStringBuilder(str);
                            //str代表要显示的全部字符串
                            String astime = atime + "";
                            style.setSpan(new ForegroundColorSpan(Color.RED), 2, 2 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                            //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                            //８代表变色到第几个字符．
                            tv_nine_title.setText(style);
                            codeLen--;
                            handlerdelay.postDelayed(this, 1000);
                        } else if (codeLen == 0 || codeLen < 0) {
                            tv_nine_title.setText("请回忆刚才所记忆数字并填写");
                            handler.removeCallbacks(this);
                            codeLen = codeLentemp;
                            tv_listener_rember.setText("");
//                            iscanvoice = true;
//                            initMusicplay("a27", subjectType + "", "");
                            tv_rember_num_content.setText("");
                            tv_rember_num_content.setVisibility(View.GONE);
                            ll_num_answer.setVisibility(View.VISIBLE);
                        }
                    }
                }, 0);
            }
        } else if ("a11".equals(voicetype)) {

        } else if ("a12".equals(voicetype)) {

        } else if ("a13".equals(voicetype)) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) img_see_img_content.getLayoutParams();
            if ("7".equals(type)) {
                layoutParams.height = DensityUtil.dip2px(context, 270);
            } else if ("8".equals(type)) {
                layoutParams.height = DensityUtil.dip2px(context, 178);
            }
            img_see_img_content.setLayoutParams(layoutParams);
            String imgimg = answerqueList.get(subjectitem).getImage();
            String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_see_img.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
            tv_nine_title.setText("请对下图进行联想记忆");
            img_see_img_content.setVisibility(View.VISIBLE);
            GlideUtils.loadRoundCircleImage(context, imgimg, img_see_img_content);
            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    /**
                     *要执行的操作
                     */
//                    initMusicplay("a14", type, "");
                    tv_ninetable_desc.setVisibility(View.GONE);
                    img_see_img_content.setVisibility(View.GONE);
                    ll_see_img_question.setVisibility(View.VISIBLE);
                    if (nineTableNunAdapter != null) {
                        nineTableNunAdapter.setGone();
                    }
                    isNineTableClick = true;
                    tv_see_img_question_title.setText(course_list_name + "联想记忆");
                    tv_select_answerA.setText(answer.get(0).getOpt_answer() + "." + answer.get(0).getOpt_answer());
                    if ("0".equals(answer.get(0).getOpt_result())) {
                        img_answerA.setImageResource(R.mipmap.icon_error_x);
                    } else {
                        img_answerA.setImageResource(R.mipmap.icon_right_g);
                    }
                    tv_select_answerB.setText(answer.get(1).getOpt_answer() + "." + answer.get(1).getOpt_answer());
                    if ("0".equals(answer.get(1).getOpt_result())) {
                        img_answerB.setImageResource(R.mipmap.icon_error_x);
                    } else {
                        img_answerB.setImageResource(R.mipmap.icon_right_g);
                    }
                    tv_select_answerC.setText(answer.get(2).getOpt_answer() + "." + answer.get(2).getOpt_answer());
                    if ("0".equals(answer.get(2).getOpt_result())) {
                        img_answerC.setImageResource(R.mipmap.icon_error_x);
                    } else {
                        img_answerC.setImageResource(R.mipmap.icon_right_g);
                    }
                }
            }, 5000);//2秒后执行Runnable中的run方法

        } else if ("a14".equals(voicetype)) {

        } else if ("a15".equals(voicetype)|| "9".equals(voicetype)|| "11".equals(voicetype)|| "10".equals(voicetype)|| "12".equals(voicetype)) {
            //词语语段
            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    /**
                     *要执行的操作
                     */
                    ll_splash.setVisibility(View.GONE);
                    unitlists.clear();
                    String contents = "";//看记换行显示
                    String contents2 = "";//看记换行显示
                    List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                    for (int i = 0; i < answer.size(); i++) {
                        String opt_answer = answer.get(i).getOpt_answer();
                        MyLog.e("词语跟读", opt_answer + "   词语跟读" + subjectType);
                        unitlists.add(opt_answer);
                        contents = contents + "\n" + opt_answer;
                        contents2 = contents2 + "  " + opt_answer;
                    }

                        ll_subject_content.setVisibility(View.VISIBLE);
                        ll_subject_content2.setVisibility(View.VISIBLE);
                        ll_ciyu_jiaocheng.setVisibility(View.GONE);
                        ll_listener_rember.setVisibility(View.VISIBLE);
                        if (nineTableAdapter != null) {
                            nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
                        }
                        //听记的内容呈现出来
                    tv_listener_rember.setVisibility(View.VISIBLE);
                        String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
                        String title = answerqueList.get(subjectitem).getTitle();
                        tv_listener_rember_title.setText(title);
                        medialists.clear();
//                        unitlists.clear();

//                    8=课内词语跟读,9=课外词语跟读,10=课外语段跟读-看记,11=课外语段跟读-听记
                        if ("10".equals(subjectType + "")) {
                            img_record.setVisibility(View.VISIBLE);
                            tv_nine_title.setText("好句速记");
                            tv_listener_rember.setText(contents);

                            if (codeLen > 0) {

                                int atime = (int) codeLen;
                                String str = "好句速记（" + atime + "s" + "）";
                                SpannableStringBuilder style = new SpannableStringBuilder(str);
                                //str代表要显示的全部字符串
                                String astime = atime + "";
                                style.setSpan(new ForegroundColorSpan(Color.RED), 5, 5 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                                //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                                //８代表变色到第几个字符．
                                tv_nine_title.setText(style);
                                codeLen--;

                                handlerdelay.postDelayed(this, 1000);
                            } else if (codeLen == 0 || codeLen < 0) {
                                tv_nine_title.setText("好句速记");
                                handler.removeCallbacks(this);
                                codeLen = codeLentemp;
                                tv_listener_rember.setText("");
                                iscanvoice = true;
                                setMusicUrl(subjectType+"", "","33");//       initMusicplay("a31", subjectType + "", "");initMusicplay("a31", subjectType + "", "");
                            }

                        }else if ("8".equals(subjectType + "")||"9".equals(subjectType + "")) {
                            tv_nine_title.setText("词语记忆测试");
                            tv_listener_rember.setText(contents);

                            if (codeLen > 0) {

                                int atime = (int) codeLen;
                                String str = "词语记忆测试（" + atime + "s" + "）";
                                SpannableStringBuilder style = new SpannableStringBuilder(str);
                                //str代表要显示的全部字符串
                                String astime = atime + "";
                                style.setSpan(new ForegroundColorSpan(Color.RED), 7, 7 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                                //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                                //８代表变色到第几个字符．
                                tv_nine_title.setText(style);
                                codeLen--;

                                handlerdelay.postDelayed(this, 1000);
                            } else if (codeLen == 0 || codeLen < 0) {
                                tv_nine_title.setText("词语记忆测试");
                                handler.removeCallbacks(this);
                                codeLen = codeLentemp;
                                tv_listener_rember.setText("");
                                tv_listener_rember.setVisibility(View.GONE);
                                ll_ci_answer.setVisibility(View.VISIBLE);
//                                iscanvoice = true;
//                                initMusicplay("a31", subjectType + "", "");
                            }

                        }else if ("17".equals(subjectType + "")) {
                            tv_nine_title.setText("单词记忆测试");
                            tv_listener_rember.setText(contents);

                            if (codeLen > 0) {

                                int atime = (int) codeLen;
                                String str = "单词记忆测试（" + atime + "s" + "）";
                                SpannableStringBuilder style = new SpannableStringBuilder(str);
                                //str代表要显示的全部字符串
                                String astime = atime + "";
                                style.setSpan(new ForegroundColorSpan(Color.RED), 7, 7 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                                //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                                //８代表变色到第几个字符．
                                tv_nine_title.setText(style);
                                codeLen--;

                                handlerdelay.postDelayed(this, 1000);
                            } else if (codeLen == 0 || codeLen < 0) {
                                tv_nine_title.setText("单词记忆测试");
                                handler.removeCallbacks(this);
                                codeLen = codeLentemp;
                                tv_listener_rember.setText("");
                                tv_listener_rember.setVisibility(View.GONE);
                                ll_ci_answer.setVisibility(View.VISIBLE);
//                                iscanvoice = true;
//                                initMusicplay("a31", subjectType + "", "");
                            }

                        }else if ("18".equals(subjectType+"")){
                            iscanvoice = true;
                            tv_nine_title.setText(getResources().getString(R.string.meiwensuji));
                            tv_listener_rember.setText(contents);
                        }else {
//                        tv_nine_title.setText("请朗读下面的内容");
                            //课内词语  课外词语
                            List<String> videourls = answerqueList.get(subjectitem).getVideo_url();
                            for (int i = 0; i < videourls.size(); i++) {
                                String url = videourls.get(i);
                                MyLog.e("词语跟读", url + "   词语跟读");
                                medialists.add(url);
                            }
                            MyLog.e("changeplay", "1864行");
                            changePlay(0, "1");//第二个参数，0代表是数字听力，1代表是词语跟读
                        }

                        if ("9".equals(subjectType + "")) {
                            tv_nine_title.setText(getResources().getString(R.string.kewaiciyu));
                        } else if ("11".equals(subjectType + "")) {
                            tv_nine_title.setText(getResources().getString(R.string.haojusuting));
                            img_record.setVisibility(View.VISIBLE);
                        }




                }
            }, 0);//2秒后执行Runnable中的run方法
        } else if ("a16".equals(voicetype)) {

        } else if ("a17".equals(voicetype)) {
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_listener_rember.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
            //听记的内容呈现出来
            tv_nine_title.setText("请朗读下面的内容");
            String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            //  8=课内词语跟读,9=课外词语跟读,10=课外语段跟读-看记,11=课外语段跟读-听记,
            String title = answerqueList.get(subjectitem).getTitle();
            tv_listener_rember_title.setText(title);
            if (answer.size() > 0) {
                String opt = answer.get(0).getOpt_answer();
                tv_listener_rember.setText(opt);
            }
        } else if ("a18".equals(voicetype)) {
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_listener_rember.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
            //听记的内容呈现出来
            tv_nine_title.setText("请朗读下面的内容");
            String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            //  8=课内词语跟读,9=课外词语跟读,10=课外语段跟读-看记,11=课外语段跟读-听记,
            String title = answerqueList.get(subjectitem).getTitle();
            tv_listener_rember_title.setText(title);
            if (answer.size() > 0) {
                String opt = answer.get(0).getOpt_answer();
                tv_listener_rember.setText(opt);
            }
        } else if ("a19".equals(voicetype)) {
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_listener_rember.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
            //听记的内容呈现出来
            tv_nine_title.setText("请朗读下面的内容");
            String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            //  8=课内词语跟读,9=课外词语跟读,10=课外语段跟读-看记,11=课外语段跟读-听记,
            String title = answerqueList.get(subjectitem).getTitle();
            tv_listener_rember_title.setText(title);
            if (answer.size() > 0) {
                String opt = answer.get(0).getOpt_answer();
                tv_listener_rember.setText(opt);
            }
        } else if ("a22".equals(voicetype)) {
            //TODO 听力选择题
            img_see_img_content.setVisibility(View.GONE);
            ll_see_img_question.setVisibility(View.VISIBLE);
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            tv_select_answerA.setText(answer.get(0).getOpt_answer() + "." + answer.get(0).getOpt_answer());
            if ("0".equals(answer.get(0).getOpt_result())) {
                img_answerA.setImageResource(R.mipmap.icon_error_x);
            } else {
                img_answerA.setImageResource(R.mipmap.icon_right_g);
            }
            tv_select_answerB.setText(answer.get(1).getOpt_answer() + "." + answer.get(1).getOpt_answer());
            if ("0".equals(answer.get(1).getOpt_result())) {
                img_answerB.setImageResource(R.mipmap.icon_error_x);
            } else {
                img_answerB.setImageResource(R.mipmap.icon_right_g);
            }
            tv_select_answerC.setText(answer.get(2).getOpt_answer() + "." + answer.get(2).getOpt_answer());
            if ("0".equals(answer.get(2).getOpt_result())) {
                img_answerC.setImageResource(R.mipmap.icon_error_x);
            } else {
                img_answerC.setImageResource(R.mipmap.icon_right_g);
            }
        } else if ("4".equals(voicetype)) {
            //九宫格笑脸

            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();
            }
            if (nineTableNunAdapter != null) {
                nineTableNunAdapter.setGone();
            }
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_nine_table.setVisibility(View.VISIBLE);

            nineTableAdapter.setData(answerqueList.get(subjectitem).getAnswer(), type, itemwidth);

            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    /**
                     *要执行的操作
                     */
                    if (codeLen > 0) {

                        int atime = (int) codeLen;
                        String str = "请" + atime + "s" + "记忆以下图形所在位置";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String astime = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 1 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);
                        codeLen--;

                        handlerdelay.postDelayed(this, 1000);
                    } else if (codeLen == 0 || codeLen < 0) {

                        int atime = (int) codeLen;
                        String str = "请" + atime + "s" + "记忆以下图形所在位置";
                        SpannableStringBuilder style = new SpannableStringBuilder(str);
                        //str代表要显示的全部字符串
                        String astime = atime + "";
                        style.setSpan(new ForegroundColorSpan(Color.RED), 1, 1 + astime.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                        //３代表从第几个字符开始变颜色，注意第一个字符序号是０．
                        //８代表变色到第几个字符．
                        tv_nine_title.setText(style);

                        handler.removeCallbacks(this);
                        codeLen = codeLentemp;

//                        initMusicplay("a02", type, "");
                        tv_nine_title.setText("请回忆刚才所记忆的图形位置");
                        tv_ninetable_desc.setVisibility(View.GONE);
                        if (nineTableAdapter != null) {
                            nineTableAdapter.setGone();
                        }
                        isNineTableClick = true;
                    }
                }
            }, 0);//2秒后执行Runnable中的run方法
        } else if ("8".equals(voicetype)) {
            //听记数字倒背正背
            tv_nine_title.setText("请按顺序背出所听到的数字");
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            ll_rember_num.setVisibility(View.VISIBLE);
            if (nineTableAdapter != null) {
                nineTableAdapter.setGone();//九宫格内容清空，为了下次出现九宫格题型
            }
            medialists.clear();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            for (int i = 0; i < answer.size(); i++) {
                String opt_answer = answer.get(i).getOpt_answer();
                MyLog.e("听记数字", opt_answer + "   听记数字");
                if ("0".equals(opt_answer)) {
                    String s = setMusicUrlName("17");
                    medialists.add(s);//medialists.add("a100");
                } else if ("1".equals(opt_answer)) {
                    String s = setMusicUrlName("18");
                    medialists.add(s);//medialists.add("a101");
                } else if ("2".equals(opt_answer)) {
                    String s = setMusicUrlName("19");
                    medialists.add(s);//medialists.add("a102");
                } else if ("3".equals(opt_answer)) {
                    String s = setMusicUrlName("20");
                    medialists.add(s);//medialists.add("a103");
                } else if ("4".equals(opt_answer)) {
                    String s = setMusicUrlName("21");
                    medialists.add(s);//medialists.add("a104");
                } else if ("5".equals(opt_answer)) {
                    String s = setMusicUrlName("22");
                    medialists.add(s);//medialists.add("a105");
                } else if ("6".equals(opt_answer)) {
                    String s = setMusicUrlName("23");
                    medialists.add(s);//medialists.add("a106");
                } else if ("7".equals(opt_answer)) {
                    String s = setMusicUrlName("24");
                    medialists.add(s);//medialists.add("a107");
                } else if ("8".equals(opt_answer)) {
                    String s = setMusicUrlName("25");
                    medialists.add(s);//medialists.add("a108");
                } else if ("9".equals(opt_answer)) {
                    String s = setMusicUrlName("26");
                    medialists.add(s);//medialists.add("a109");
                }

            }

            MyLog.e("changeplay", "2027行");
            changePlay(0, "0");//第二个参数，0代表是数字听力，1代表是词语跟读
        } else if ("7".equals(voicetype)) {
            tv_nine_title.setText("请按顺序背出所看到的数字");
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            rl_shan_num.setVisibility(View.VISIBLE);
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            int size = answer.size();

            shanitem = 0;
            handlerdelay.postDelayed(new Runnable() {
                @Override
                public void run() {
                    tv_shannum_num.clearAnimation();
                    if (shanitem < size) {
                        long dtime = (long) (codeLen * 1000);
                        // 1. fromAlpha:动画开始时视图的透明度(取值范围: -1 ~ 1)
                        // 2. toAlpha:动画结束时视图的透明度(取值范围: -1 ~ 1)
                        Animation alphaAnimation = new AlphaAnimation(1, 0);
                        alphaAnimation.setDuration(dtime);
                        alphaAnimation.setRepeatCount(1);
                        alphaAnimation.setFillAfter(true);
                        tv_shannum_num.startAnimation(alphaAnimation);
                        tv_shannum_num.setText(answer.get(shanitem).getOpt_answer());


                        shanitem++;

                        handlerdelay.postDelayed(this, dtime);
                    } else {
                        tv_shannum_num.setText("");
                        iscanvoice = true;
                        setMusicUrl(subjectType+"", "","15");//        initMusicplay("a27", subjectType + "", "");initMusicplay("a27", subjectType + "", "");
                    }
                }
            }, 0);//2秒后执行Runnable中的run方法
        } else if ("2".equals(voicetype)) {
//            tv_nine_title.setText("请按顺序背出所看到的数字");
            ll_splash.setVisibility(View.GONE);
            ll_subject_content.setVisibility(View.VISIBLE);
            ll_subject_content2.setVisibility(View.VISIBLE);
            ll_ciyu_jiaocheng.setVisibility(View.GONE);
            rl_long_num.setVisibility(View.VISIBLE);
            String course_list_name = answerqueList.get(subjectitem).getCourse_list_name();
            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
            int size = answer.size();
            String str = "";
            if (size > 0) {
                str = answer.get(0).getOpt_answer();
            }
            tv_long_num_que.setText("问题1："+str);
            tv_longnum_num.setText(course_list_name);
            tv_longnum_num.setMovementMethod(ScrollingMovementMethod.getInstance());
            tv_nine_title.setText("根据问题观察下面数字");
        }

    }

    int shanitem = 0;
    int longqueitem = 0;

    public void setLongNumQuestion(int item) {
        List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
        int size = answer.size();
        if (item < size) {
            et_longnum_input.setText("");
            tv_longnum_question_title.setText(answer.get(item).getOpt_answer());
        } else {
            ToastUtils.show("已全部做完");
        }

    }

    /**
     * 参数设置
     *
     * @return
     */
    public void setParam() {
        // 清空参数
        mIat.setParameter(SpeechConstant.PARAMS, null);

        // 设置听写引擎
        mIat.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
        // 设置返回结果格式
        mIat.setParameter(SpeechConstant.RESULT_TYPE, resultType);


        mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
        // 设置语言区域
        mIat.setParameter(SpeechConstant.ACCENT, "mandarin");

        Log.e(TAG, "last language:" + mIat.getParameter(SpeechConstant.LANGUAGE));

        //此处用于设置dialog中不显示错误码信息
        //mIat.setParameter("view_tips_plain","false");

        // 设置语音前端点:静音超时时间，即用户多长时间不说话则当做超时处理
        mIat.setParameter(SpeechConstant.VAD_BOS, "4000");

        // 设置语音后端点:后端点静音检测时间，即用户停止说话多长时间内即认为不再输入， 自动停止录音
        mIat.setParameter(SpeechConstant.VAD_EOS, "15000");

        // 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
        mIat.setParameter(SpeechConstant.ASR_PTT, "1");

        // 设置音频保存路径，保存音频格式支持pcm、wav，设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
        mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
        mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory() + "/msc/iat.wav");
    }

    /**
     * 初始化监听器。
     */
    private InitListener mInitListener = new InitListener() {

        @Override
        public void onInit(int code) {
            Log.d(TAG, "SpeechRecognizer init() code = " + code);
            if (code != ErrorCode.SUCCESS) {
                MyLog.e("初始化失败，错误码：" + code, ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
            }
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;
        }
        if (null != mIat) {
            // 退出时释放连接
            mIat.cancel();
            mIat.destroy();
        }
        if (customProgressDialog != null) {
            if (customProgressDialog.isShowing()) {
                customProgressDialog.dismiss();
            }
        }
    }



    private void printResult(RecognizerResult results) {
        String text = JsonParser.parseIatResult(results.getResultString());

        String sn = null;
        // 读取json结果中的sn字段
        try {
            JSONObject resultJson = new JSONObject(results.getResultString());
            sn = resultJson.optString("sn");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        mIatResults.put(sn, text);

        StringBuffer resultBuffer = new StringBuffer();
        for (String key : mIatResults.keySet()) {
            resultBuffer.append(mIatResults.get(key));
        }
        voiceContent = resultBuffer.toString();
        MyLog.e("识别内容", resultBuffer.toString());

//        mResultText.setText(resultBuffer.toString());
//        mResultText.setSelection(mResultText.length());
    }

    /**
     * 获取屏幕宽度
     */
    private void getScreenDen() {

        WindowManager manager = getWindowManager();
        DisplayMetrics dm = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(dm);
        //以要素为单位
        screenwidth = dm.widthPixels;
        screenheightPixels = dm.heightPixels;
        MyLog.e("获取屏幕高度", screenheightPixels + "    高度   " + screenwidth);
    }


    /**
     * 听写监听器。
     */
    private RecognizerListener mRecognizerListener = new RecognizerListener() {

        @Override
        public void onBeginOfSpeech() {
            // 此回调表示：sdk内部录音机已经准备好了，用户可以开始语音输入

            //听记
            img_listener_floor.setVisibility(View.VISIBLE);
            img_listener_floor.setImageResource(R.mipmap.icon_second_floor);
//            ToastUtils.show("开始说话");
        }

        @Override
        public void onError(SpeechError error) {
            // Tips：
            // 错误码：10118(您没有说话)，可能是录音机权限被禁，需要提示用户打开应用的录音权限。

            ToastUtils.show("还未听到您说话呢");
//            ToastUtils.show(error.getPlainDescription(true));

        }

        @Override
        public void onEndOfSpeech() {
            // 此回调表示：检测到了语音的尾端点，已经进入识别过程，不再接受语音输入
//            ToastUtils.show("结束说话");
        }

        @Override
        public void onResult(RecognizerResult results, boolean isLast) {
            printResult(results);
            if (isLast) {
                mIatResults.clear();
                //课程类型:0=九宫格心形,1=九宫格星星,2=九宫格笑脸,3=九宫格五角星,4=听记,5=数字听力,6=数字位置,7=点的记忆,8=图形记忆
                MyLog.e("慧学慧记音频识别", isLast + "   结束");
                int type = answerqueList.get(subjectitem).getType() - 1;
                List<AnswerQuesBean.DataBean.AnswerBean> answer1 = answerqueList.get(subjectitem).getAnswer();
                int size1 = answer1.size();
                String answerstr1 = "";
                for (int i = 0;i<size1;i++){
                    answerstr1 = answerstr1+answer1.get(i).getOpt_answer();
                }
                float xiangsimain = xiangsimain(voiceContent,answerstr1);
                MyLog.e("语音录音",voiceContent+"  =  "+answerstr1 +"   相似度="+xiangsimain);
                if (xiangsimain > 0.75){
                    //答案正确
                    if (type == 10){
                        myapp.scorekanji = myapp.scorekanji+4;
                    }else if (type == 11){
                        myapp.scoretingji = myapp.scoretingji+4;
                    }
                }else{

                }
                if ("6".equals(type + "") || "7".equals(type + "") || "15".equals(type + "")) {
                    String str = "";
                    String[] split = voiceContent.split("");
                    for (int i = 0; i < split.length; i++) {
                        String s = split[i];
                        if (s.equals("0") || s.equals("1") || s.equals("2") || s.equals("3")
                                || s.equals("4") || s.equals("5") || s.equals("6") || s.equals("7")
                                || s.equals("8") || s.equals("9")) {
                            str = str + s;
                        }
                    }
                    if ("".equals(voicenumberstr)) {
                        voicenumberstr = str;
                        //正背结束，开始倒背
                        if ("".equals(voicenumberstr)) {
                            ToastUtils.show("还未听到您说话呢");
                            setMusicUrl(subjectType+"", "","15");//       initMusicplay("a27", subjectType + "", ""); initMusicplay("a27", subjectType + "", "");
                        } else {
                            setMusicUrl(subjectType+"", "","16");//       initMusicplay("a28", subjectType + "", "");initMusicplay("a28", subjectType + "", "");
                        }
                    } else {
                        if ("".equals(str)) {
                            ToastUtils.show("还未听到你说数字哦");
                        } else {
                            voicenumberstrback = str;
                            tv_rember_num_content.setTextColor(getResources().getColor(R.color.color333));
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String aaa = numberstr + "\n正背：" + voicenumberstr + "\n倒背：" + voicenumberstrback;
                                    tv_rember_num_content.setText(aaa);
                                    if ("6".equals(type + "")|| "15".equals(type + "")) {
                                        //看记
                                        setMusicUrl(type+"", "","13");//       initMusicplay("a34", type + "", "");initMusicplay("a34", type + "", "");
                                    }else{
                                        //听记
                                        setMusicUrl(type+"", "","30");//       initMusicplay("a35", type + "", "");initMusicplay("a35", type + "", "");
                                    }
                                    iscanvoice = false;
                                    voicenumberstr = "";
                                }
                            });
                        }


                    }

                    MyLog.e("是否可以录音", iscanvoice + "   2128行");

                } else if ("10".equals(type + "") || "11".equals(type + "") || "8".equals(type + "") || "9".equals(type + "")) {
                    if ("".equals(voiceContent)) {
                        ToastUtils.show("还未听到您说话呢");
                    } else {
                        String str = "";
                        for (int i = 0; i < unitlists.size(); i++) {
                            String s = unitlists.get(i);
                            str = str + "  " + s;
                        }
                        tv_listener_rember.setText("标准答案：" + str);

                        /*if (xiangsimain > 0.75){
                            initMusicplay("a03", type + "", "");
                        }else{
                            initMusicplay("a04", type + "", "");
                        }*/
                        iscanvoice = false;
                    }
                } else if ("14".equals(type + "")) {
                    if ("".equals(voiceContent)) {
                        ToastUtils.show("还未听到您说话呢");
                    } else {
                        String stranswer = "";
                        String[] split = voiceContent.split("");
                        for (int i = 0; i < split.length; i++) {
                            String s = split[i];
                            if (s.equals("0") || s.equals("1") || s.equals("2") || s.equals("3")
                                    || s.equals("4") || s.equals("5") || s.equals("6") || s.equals("7")
                                    || s.equals("8") || s.equals("9")) {
                                stranswer = stranswer + s;
                            }
                        }
                        if ("".equals(stranswer)) {
                            ToastUtils.show("还未听到您说数字呢");
                        } else {
                            List<AnswerQuesBean.DataBean.AnswerBean> answer = answerqueList.get(subjectitem).getAnswer();
                            int size = answer.size();

                            String str = "";
                            for (int i = 0; i < size; i++) {
                                String s = answer.get(i).getOpt_answer();
                                str = str + s;
                            }
                            ll_shan_content.setVisibility(View.VISIBLE);
                            tv_shan_question.setText(str);
                            tv_shan_answer.setText(stranswer);
                            iscanvoice = false;
                            setMusicUrl(subjectType+"", "","31");//initMusicplay("a12", type + "", "");
                        }


                    }
                } else {
                    setMusicUrl(subjectType+"", "","31");//initMusicplay("a12", type + "", "");
                }
            }
        }

        @Override
        public void onVolumeChanged(int volume, byte[] data) {
//            ToastUtils.show("当前正在说话，音量大小：" + volume);

            //听记
            if (volume > 15) {
                img_listener_floor.setImageResource(R.mipmap.icon_second_floor);
            } else {
                img_listener_floor.setImageResource(R.mipmap.icon_second_floor);
            }
            MyLog.d(TAG, volume + "   返回音频数据：" + data.length);
        }

        @Override
        public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
            // 以下代码用于获取与云端的会话id，当业务出错时将会话id提供给技术支持人员，可用于查询会话日志，定位出错原因
            // 若使用本地能力，会话id为null
            //	if (SpeechEvent.EVENT_SESSION_ID == eventType) {
            //		String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
            //		Log.d(TAG, "session id =" + sid);
            //	}
        }
    };
    int startindex = -1;
    int endindex = -1;
    boolean iscancle = false;
    Timer timer = null;
    private MyTimerTask mTask = null;

    private class MyTimerTask extends TimerTask {

        @Override
        public void run() {
            if (iscancle) {
                mTask.cancel();
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    startindex++;
                    endindex++;
                    tv_rember_num_content.setTextColor(Color.TRANSPARENT);
                    if (startindex < numberstr.length()) {
                        SpannableStringBuilder spannable = new SpannableStringBuilder(numberstr);
                        spannable.setSpan(new ForegroundColorSpan(Color.BLACK), startindex, endindex + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        tv_rember_num_content.setText(spannable);
                        iscancle = false;
                    } else {
                        iscancle = true;
//                        timer.cancel();
                        tv_rember_num_content.setText("");
                        setMusicUrl(subjectType+"", "","15");//       initMusicplay("a27", subjectType + "", "");initMusicplay("a27", subjectType + "", "");
                        iscanvoice = true;
                        MyLog.e("是否可以录音", iscanvoice + "   2258行");
                    }

                }
            });
        }
    }

    public int currentposi = 0;

    public void changePlay(int position, String videotype) {
        MyLog.e("顺序播放音频", position + "顺序播放音频");
        currentposi = position;
        stopPlay();
        int size = medialists.size();
        Uri sound = null;
        if (currentposi == -1) {
            return;
        }
        if (currentposi < size) {
            try {
                if ("1".equals(videotype)) {
                    if (!"11".equals(subjectType + "")) {
                        String s1 = tv_listener_rember.getText().toString();
                        tv_listener_rember.setText(s1 + "  " + unitlists.get(position));
                    }

                }
                String s = medialists.get(currentposi);
                if (mediaPlayer == null) {
                    mediaPlayer = new MediaPlayer();
                    // 切歌之前先重置，释放掉之前的资源
                    mediaPlayer.reset();
                    if ("0".equals(videotype)) {
//                        sound = MusicUri.getMusic(s, context);
//                        mediaPlayer.setDataSource(context, sound);  //添加数据源
                        File file = new File("/storage/emulated/0/test_music/", s + ".mp3");

                        if (file.exists()) {
                            MyLog.e("打印路径", file.getPath() + "   打印路径");
                            mediaPlayer.setDataSource(file.getPath());
                        }
                    } else if ("1".equals(videotype)) {
                        if (!"".equals(s)) {
                            String userInfo = getUserInfo(s);
                            if (userInfo != null || !"".equals(userInfo)) {
                                File file = new File("/storage/emulated/0/test_music/", userInfo + ".mp3");
                                if (file.exists()) {
                                    MyLog.e("打印路径", file.getPath() + "   打印路径");
                                    mediaPlayer.setDataSource(file.getPath());
                                } else {
//                                    ToastUtils.show("音频文件路径未找到");
                                    MyLog.e("打印路径", "   文件不存在");
                                    mediaPlayer.setDataSource(s);  //添加数据源
                                }
                            } else {
                                mediaPlayer.setDataSource(s);  //添加数据源
                            }

                        } else {
                            try {
                                Thread.currentThread().sleep(1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            mediaPlayer.release();
                            mediaPlayer = null;
                            currentposi++;
                            MyLog.e("changeplay", "3339行");
                            changePlay(currentposi, videotype);
                            MyLog.e("音频播放完毕", "音频播放完毕");
                        }
                    }


                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);   //设置流媒体的类型，AudioManager可以修改系统的情景模式为音乐 可以后台播放

                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {//准备完毕后调用
                        @Override
                        public void onPrepared(MediaPlayer mediaPlayer) {
                            mediaPlayer.start();//开始播放音乐
                        }
                    });
                    mediaPlayer.prepareAsync();//异步准备
                    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {//放完一首歌后调用
                        @Override
                        public void onCompletion(MediaPlayer mp) {
                            mediaPlayer.release();
                            mediaPlayer = null;
                            currentposi++;
                            MyLog.e("changeplay", "2420行");
                            changePlay(currentposi, videotype);
                            MyLog.e("音频播放完毕", "音频播放完毕");
                        }
                    });

                }
            } catch (Exception e) {

            }
        } else {
            iscanvoice = true;
            tv_listener_rember.setText("");
            if ("7".equals(subjectType + "")) {
                //听记数字
                setMusicUrl(subjectType+"", "","15");//       initMusicplay("a27", subjectType + "", "");initMusicplay("a27", subjectType + "", "");
            } else if ("8".equals(subjectType + "") || "9".equals(subjectType + "")) {
                //课内词语跟读，课外词语跟读
                setMusicUrl(subjectType+"", "","33");//       initMusicplay("a30", subjectType + "", ""); initMusicplay("a30", subjectType + "", "");
            } else if ("10".equals(subjectType + "")) {
                //语段看记
                tv_listener_rember.setText("");
                setMusicUrl(subjectType+"", "","33");//       initMusicplay("a31", subjectType + "", "");initMusicplay("a31", subjectType + "", "");
            } else if ("11".equals(subjectType + "")) {
                //语段听记
                tv_listener_rember.setText("");
                setMusicUrl(subjectType+"", "","33");//       initMusicplay("a31", subjectType + "", "");initMusicplay("a31", subjectType + "", "");
            }

        }
    }


    public static float xiangsimain(String a,String b) {
//        String a= "中，华人，民共和国，";
//        String b = "中华人民共和国，万岁";
        float similarityRatio = getSimilarityRatio(a, b);
        System.out.println("相似度："+similarityRatio);
        return similarityRatio;
    }
    /**
     * 获取两字符串的相似度
     */
    public static float getSimilarityRatio(String str, String target) {
        int max = Math.max(str.length(), target.length());
        return 1 - (float) compare(str, target) / max;
    }
    /**
     * 比较两个字符串的相识度
     * 核心算法：用一个二维数组记录每个字符串是否相同，如果相同记为0，不相同记为1，每行每列相同个数累加
     * 则数组最后一个数为不相同的总数，从而判断这两个字符的相识度
     */
    private static int compare(String str, String target) {
        int d[][]; // 矩阵
        int n = str.length();
        int m = target.length();
        int i; // 遍历str的
        int j; // 遍历target的
        char ch1; // str的
        char ch2; // target的
        int temp; // 记录相同字符,在某个矩阵位置值的增量,不是0就是1
        if (n == 0) {
            return m;
        }
        if (m == 0) {
            return n;
        }
        d = new int[n + 1][m + 1];
// 初始化第一列
        for (i = 0; i <= n; i++) {
            d[i][0] = i;
        }
// 初始化第一行
        for (j = 0; j <= m; j++) {
            d[0][j] = j;
        }
        for (i = 1; i <= n; i++) {
// 遍历str
            ch1 = str.charAt(i - 1);
// 去匹配target
            for (j = 1; j <= m; j++) {
                ch2 = target.charAt(j - 1);
                if (ch1 == ch2 || ch1 == ch2 + 32 || ch1 + 32 == ch2) {
                    temp = 0;
                } else {
                    temp = 1;
                }
// 左边+1,上边+1, 左上角+temp取最小
                d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + temp);
            }
        }
        return d[n][m];
    }
    /**
     * 获取最小的值
     */
    private static int min(int one, int two, int three) {
        return (one = one < two ? one : two) < three ? one : three;
    }

    /**
     * 隐藏软键盘(只适用于Activity，不适用于Fragment)
     */
    public static void hideSoftKeyboard(Activity activity) {
        View view = activity.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    public void setMusicUrl(String type,String onlinemusic,String musicid){
        if ("".equals(musicid)){
            //单词记忆
            initMusicplay("", type, "","");
        }else{
            String oneKeyForId = getOneKeyForId(musicid);
            String key = getUserInfo(oneKeyForId);
            String userInfo = getUserInfo(key);
            initMusicplay(userInfo, type, onlinemusic,musicid);//        initMusicplay("a01", "", "");
        }
    }
    public String setMusicUrlName(String musicid){
        String userInfo = "";
        String oneKeyForId = getOneKeyForId(musicid);
        String key = getUserInfo(oneKeyForId);
        userInfo = getUserInfo(key);
        return userInfo;
    }

}
